ocr: ensure forked logging handlers also work under pytest

This commit is contained in:
Robert Sachunsky 2026-07-18 18:02:40 +02:00
parent 79a9bb0128
commit 4f7c5675fc
3 changed files with 11 additions and 6 deletions

View file

@ -51,7 +51,7 @@ def _run_single(*args, **kwargs):
logq = kwargs.pop('logq') logq = kwargs.pop('logq')
# replace all inherited handlers with queue handler # replace all inherited handlers with queue handler
logging.root.handlers.clear() logging.root.handlers.clear()
_instance.logger.handlers.clear() _instance.logger.parent.handlers.clear()
handler = logging.handlers.QueueHandler(logq) handler = logging.handlers.QueueHandler(logq)
logging.root.addHandler(handler) logging.root.addHandler(handler)
return _instance.run_single(*args, **kwargs) return _instance.run_single(*args, **kwargs)
@ -494,7 +494,9 @@ class Eynollah_ocr(Eynollah):
for job in as_completed(list(jobs)): for job in as_completed(list(jobs)):
img_filename, logq = jobs[job] img_filename, logq = jobs[job]
loglistener = logging.handlers.QueueListener( loglistener = logging.handlers.QueueListener(
logq, *self.logger.handlers, respect_handler_level=False) logq, *self.logger.handlers,
*self.logger.parent.handlers,
respect_handler_level=False)
try: try:
loglistener.start() loglistener.start()
job.result() job.result()

View file

@ -24,7 +24,7 @@ MODEL_VRAM_LIMITS = {
"region_fl_np": 1756, "region_fl_np": 1756,
"table": 1818, "table": 1818,
"reading_order": 632, "reading_order": 632,
"ocr": 2400, # 850 for bs 8 "ocr": 2600, # 850 for bs 8
} }
class EynollahModelZoo: class EynollahModelZoo:
@ -390,7 +390,9 @@ class EynollahModelZoo:
if isinstance(provider0, tuple): if isinstance(provider0, tuple):
provider0 = provider0[0] provider0 = provider0[0]
self.logger.info("using %s with ONNX provider %s for model %s", self.logger.info("using %s with ONNX provider %s for model %s",
"GPU %d" % gpu if gpu >= 0 else "CPU", "GPU %d" % gpu if (gpu >= 0 and not
provider0.startswith("CPU"))
else "CPU",
provider0[:-17], model_category) provider0[:-17], model_category)
model = ort.InferenceSession( model = ort.InferenceSession(
model_path, model_path,

View file

@ -30,7 +30,7 @@ def test_run_eynollah_ocr_filename(
'-o', str(outfile.parent), '-o', str(outfile.parent),
] + options, ] + options,
[ [
'output filename:' str(infile)
] ]
) )
assert outfile.exists() assert outfile.exists()
@ -57,7 +57,8 @@ def test_run_eynollah_ocr_directory(
'-o', str(outdir), '-o', str(outdir),
], ],
[ [
'output filename:' 'Job done in',
'All jobs done in',
] ]
) )
assert len(list(outdir.iterdir())) == 2 assert len(list(outdir.iterdir())) == 2