Make progress pool common rather than plugin-specific

This commit is contained in:
James R. Barlow
2021-01-24 23:56:09 -08:00
parent 3bd5054634
commit 386cabff00
3 changed files with 32 additions and 35 deletions
+13 -9
View File
@@ -4,8 +4,11 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import threading
from typing import Callable, Iterable, Optional
pool_lock = threading.Lock()
def _task_noop(*_args, **_kwargs):
return
@@ -35,12 +38,13 @@ def exec_progress_pool(
if not task_finished:
task_finished = _task_noop
_model(
use_threads=use_threads,
max_workers=max_workers,
tqdm_kwargs=tqdm_kwargs,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
)
with pool_lock:
_model(
use_threads=use_threads,
max_workers=max_workers,
tqdm_kwargs=tqdm_kwargs,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
)
+11 -14
View File
@@ -31,8 +31,6 @@ from ocrmypdf.exceptions import InputFileError
Queue = Union[multiprocessing.Queue, queue.Queue]
pool_lock = threading.Lock()
def log_listener(q: Queue):
"""Listen to the worker processes and forward the messages to logging
@@ -120,18 +118,17 @@ def exec_progress_pool(
worker_initializer = _noop
with pool_lock:
_exec_progress_pool(
max_workers=max_workers,
tqdm_kwargs=tqdm_kwargs,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
log_queue=log_queue,
pool_class=pool_class,
initializer=initializer,
)
_exec_progress_pool(
max_workers=max_workers,
tqdm_kwargs=tqdm_kwargs,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
log_queue=log_queue,
pool_class=pool_class,
initializer=initializer,
)
def _exec_progress_pool(
+8 -12
View File
@@ -11,7 +11,6 @@
import logging
import logging.handlers
import signal
import threading
from contextlib import suppress
from enum import Enum, auto
from itertools import islice, repeat, takewhile, zip_longest
@@ -23,8 +22,6 @@ from unittest.mock import Mock
from ocrmypdf import hookimpl
from ocrmypdf.exceptions import InputFileError
pool_lock = threading.Lock()
class MessageType(Enum):
exception = auto()
@@ -101,15 +98,14 @@ def lambda_pool_impl(
task_finished(result, pbar)
return
with pool_lock:
_lambda_pool_impl(
max_workers=max_workers,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
pbar=pbar,
)
_lambda_pool_impl(
max_workers=max_workers,
worker_initializer=worker_initializer,
task=task,
task_arguments=task_arguments,
task_finished=task_finished,
pbar=pbar,
)
def _lambda_pool_impl(