From 6ee1d14c9a8b81e5a69f1011596d0b5c0fe39b4a Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Mon, 19 Feb 2024 17:18:27 +0200 Subject: [PATCH] Start conversion process earlier Start the conversion process earlier, so that we have a reference to the Popen object in case of an exception. --- dangerzone/isolation_provider/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index 54eb13e..6becee6 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -69,9 +69,11 @@ class IsolationProvider(ABC): self.progress_callback = progress_callback document.mark_as_converting() try: + conversion_proc = self.start_doc_to_pixels_proc() with tempfile.TemporaryDirectory() as t: Path(f"{t}/pixels").mkdir() - self.doc_to_pixels(document, t) + self.doc_to_pixels(document, t, conversion_proc) + conversion_proc.wait(3) # TODO: validate convert to pixels output self.pixels_to_pdf(document, t, ocr_lang) document.mark_as_safe() @@ -91,10 +93,11 @@ class IsolationProvider(ABC): self.print_progress(document, True, str(e), 0) document.mark_as_failed() - def doc_to_pixels(self, document: Document, tempdir: str) -> None: + def doc_to_pixels( + self, document: Document, tempdir: str, p: subprocess.Popen + ) -> None: percentage = 0.0 with open(document.input_filename, "rb") as f: - p = self.start_doc_to_pixels_proc() try: assert p.stdin is not None p.stdin.write(f.read())