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}"