mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-10-06 22:50:14 +02:00
ProcessPoolExecutor: shutdown during del() instead of atexit()
This commit is contained in:
parent
08c8c26028
commit
b21051db21
1 changed files with 20 additions and 1 deletions
|
@ -260,7 +260,6 @@ class Eynollah:
|
||||||
|
|
||||||
# for parallelization of CPU-intensive tasks:
|
# for parallelization of CPU-intensive tasks:
|
||||||
self.executor = ProcessPoolExecutor(max_workers=cpu_count())
|
self.executor = ProcessPoolExecutor(max_workers=cpu_count())
|
||||||
atexit.register(self.executor.shutdown)
|
|
||||||
|
|
||||||
if threshold_art_class_layout:
|
if threshold_art_class_layout:
|
||||||
self.threshold_art_class_layout = float(threshold_art_class_layout)
|
self.threshold_art_class_layout = float(threshold_art_class_layout)
|
||||||
|
@ -406,6 +405,26 @@ class Eynollah:
|
||||||
|
|
||||||
self.logger.info(f"Model initialization complete ({time.time() - t_start:.1f}s)")
|
self.logger.info(f"Model initialization complete ({time.time() - t_start:.1f}s)")
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
if hasattr(self, 'executor') and getattr(self, 'executor'):
|
||||||
|
self.executor.shutdown()
|
||||||
|
for model_name in ['model_page',
|
||||||
|
'model_classifier',
|
||||||
|
'model_bin',
|
||||||
|
'model_enhancement',
|
||||||
|
'model_region',
|
||||||
|
'model_region_1_2',
|
||||||
|
'model_region_p2',
|
||||||
|
'model_region_fl_np',
|
||||||
|
'model_region_fl',
|
||||||
|
'model_textline',
|
||||||
|
'model_reading_order',
|
||||||
|
'model_table',
|
||||||
|
'model_ocr',
|
||||||
|
'processor']:
|
||||||
|
if hasattr(self, model_name) and getattr(self, model_name):
|
||||||
|
delattr(self, model_name)
|
||||||
|
|
||||||
def cache_images(self, image_filename=None, image_pil=None, dpi=None):
|
def cache_images(self, image_filename=None, image_pil=None, dpi=None):
|
||||||
ret = {}
|
ret = {}
|
||||||
t_c0 = time.time()
|
t_c0 = time.time()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue