From 7cf2c543b77efdae776ff43904c10875296e8799 Mon Sep 17 00:00:00 2001 From: ipitio <21136719+ipitio@users.noreply.github.com> Date: Wed, 9 Oct 2024 16:31:31 -0400 Subject: [PATCH] try --- src/main.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index fab4dd1..d43a9db 100644 --- a/src/main.py +++ b/src/main.py @@ -36,11 +36,13 @@ def predict(input_file: Path, output_file: Path): doc.insert_pdf(fitz.open("pdf", prediction)) gc.collect() - # Save the OCR results to a new PDF file - doc.save(output_file, garbage=4, deflate=True) - doc.close() - input_file.unlink() - print(f"Processed {relative_path}") + try: + input_file.unlink() + finally: + # Save the OCR results to a new PDF file + doc.save(output_file, garbage=4, deflate=True) + doc.close() + print(f"Processed {relative_path}") Parallel(n_jobs=-1)( delayed(predict)(Path(root) / file, Path(root.replace("todo", "done")) / file)