chore: Safer unloading of DPv4 backend (#1867)

fix: Safer unloading of DPv4 backend

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
Christoph Auer
2025-06-30 14:41:21 +02:00
committed by GitHub
parent ae39a9411a
commit bdfee4e2d0
3 changed files with 1262 additions and 344 deletions

View File

@@ -187,7 +187,17 @@ class DoclingParseV4DocumentBackend(PdfDocumentBackend):
def unload(self):
super().unload()
self.dp_doc.unload()
with pypdfium2_lock:
self._pdoc.close()
self._pdoc = None
# Unload docling-parse document first
if self.dp_doc is not None:
self.dp_doc.unload()
self.dp_doc = None
# Then close pypdfium2 document with proper locking
if self._pdoc is not None:
with pypdfium2_lock:
try:
self._pdoc.close()
except Exception:
# Ignore cleanup errors
pass
self._pdoc = None