mirror of
https://github.com/ocrmypdf/OCRmyPDF.git
synced 2026-01-05 19:51:07 +00:00
Add option to use threads instead of processes
Mainly since they are more convenient for debugging
This commit is contained in:
parent
522e1e948b
commit
45a361d112
@ -164,6 +164,10 @@ def worker_init(queue):
|
||||
root.addHandler(h)
|
||||
|
||||
|
||||
def worker_thread_init(queue):
|
||||
pass
|
||||
|
||||
|
||||
def log_listener(queue):
|
||||
"""Listen to the worker processes and forward the messages to logging
|
||||
|
||||
@ -196,6 +200,14 @@ def exec_concurrent(context):
|
||||
if max_workers > 1:
|
||||
context.log.info("Start processing %d pages concurrent" % max_workers)
|
||||
|
||||
if context.options.use_threads:
|
||||
from multiprocessing.dummy import Pool
|
||||
|
||||
initializer = worker_thread_init
|
||||
else:
|
||||
Pool = multiprocessing.Pool
|
||||
initializer = worker_init
|
||||
|
||||
sidecars = [None] * len(context.pdfinfo)
|
||||
ocrgraft = OcrGrafter(context)
|
||||
|
||||
@ -208,8 +220,8 @@ def exec_concurrent(context):
|
||||
unit='page',
|
||||
unit_scale=0.5,
|
||||
disable=not context.options.progress_bar,
|
||||
) as pbar, multiprocessing.Pool(
|
||||
processes=max_workers, initializer=worker_init, initargs=(log_queue,)
|
||||
) as pbar, Pool(
|
||||
processes=max_workers, initializer=initializer, initargs=(log_queue,)
|
||||
) as pool:
|
||||
results = pool.imap_unordered(exec_page_sync, context.get_page_contexts())
|
||||
while True:
|
||||
|
||||
@ -153,6 +153,7 @@ def ocrmypdf( # pylint: disable=unused-argument
|
||||
output_type=None,
|
||||
sidecar=None,
|
||||
jobs=None,
|
||||
use_threads=None,
|
||||
title=None,
|
||||
author=None,
|
||||
subject=None,
|
||||
|
||||
@ -199,6 +199,7 @@ jobcontrol.add_argument(
|
||||
dest='progress_bar',
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
jobcontrol.add_argument('--use-threads', action='store_true', help=argparse.SUPPRESS)
|
||||
|
||||
metadata = parser.add_argument_group(
|
||||
"Metadata options",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user