From d412c363d73ac5944956bd5d2c1bb48e8f46ad7a Mon Sep 17 00:00:00 2001 From: Fasal Shah Date: Tue, 8 Oct 2024 14:16:43 +0530 Subject: [PATCH] fixed unload pdf backend resources (#129) Signed-off-by: faisal shah Co-authored-by: faisal shah --- docling/document_converter.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docling/document_converter.py b/docling/document_converter.py index a4c55ab..3eac36d 100644 --- a/docling/document_converter.py +++ b/docling/document_converter.py @@ -199,9 +199,6 @@ class DocumentConverter: end_pb_time = time.time() - start_pb_time _log.info(f"Finished converting page batch time={end_pb_time:.3f}") - # Free up mem resources of PDF backend - in_doc._backend.unload() - conv_res.pages = all_assembled_pages self._assemble_doc(conv_res) @@ -227,6 +224,11 @@ class DocumentConverter: f"{trace}" ) + finally: + # Always unload the PDF backend, even in case of failure + if in_doc._backend: + in_doc._backend.unload() + end_doc_time = time.time() - start_doc_time _log.info( f"Finished converting document time-pages={end_doc_time:.2f}/{in_doc.page_count}"