From 0ae28f7d3ef33d6bf3650b99bc7646c3234341d1 Mon Sep 17 00:00:00 2001 From: Robert Sachunsky Date: Sat, 14 Dec 2024 12:15:56 +0000 Subject: [PATCH] switch from stdlib to loky.ProcessPoolExecutor, ensure shutdown --- requirements.txt | 1 + src/eynollah/eynollah.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index d72df29..ef3fe31 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ scikit-learn >= 0.23.2 tensorflow < 2.13 imutils >= 0.5.3 numba <= 0.58.1 +loky diff --git a/src/eynollah/eynollah.py b/src/eynollah/eynollah.py index 28cb330..8139b11 100644 --- a/src/eynollah/eynollah.py +++ b/src/eynollah/eynollah.py @@ -10,11 +10,12 @@ import math import os import sys import time +import atexit import warnings from functools import partial from pathlib import Path from multiprocessing import cpu_count -from concurrent.futures import ProcessPoolExecutor +from loky import ProcessPoolExecutor import gc from ocrd_utils import getLogger import cv2 @@ -257,7 +258,8 @@ class Eynollah: pcgts=pcgts) self.logger = logger if logger else getLogger('eynollah') # for parallelization of CPU-intensive tasks: - self.executor = ProcessPoolExecutor(max_workers=cpu_count()) + self.executor = ProcessPoolExecutor(max_workers=cpu_count(), timeout=1200) + atexit.register(self.executor.shutdown) self.dir_models = dir_models self.model_dir_of_enhancement = dir_models + "/eynollah-enhancement_20210425" self.model_dir_of_binarization = dir_models + "/eynollah-binarization_20210425"