Compare commits

...

2 commits

Author SHA1 Message Date
Alexis Métaireau
f6a616f23b
FIXUP: use proc_stderr when needed 2025-01-13 16:15:10 +01:00
Alexis Métaireau
3b961e6b90
FIXUP: Do not attach the stderr to the base object 2025-01-13 16:08:16 +01:00
3 changed files with 7 additions and 8 deletions

View file

@ -94,8 +94,6 @@ class IsolationProvider(ABC):
self.proc_stderr = subprocess.PIPE
else:
self.proc_stderr = subprocess.DEVNULL
# Store the proc stderr in memory
self.stderr = BytesIO()
def should_capture_stderr(self) -> bool:
return self.debug or getattr(sys, "dangerzone_dev", False)
@ -335,8 +333,10 @@ class IsolationProvider(ABC):
timeout_force: int = TIMEOUT_FORCE,
) -> Iterator[subprocess.Popen]:
"""Start a conversion process, pass it to the caller, and then clean it up."""
# Store the proc stderr in memory
stderr = BytesIO()
p = self.start_doc_to_pixels_proc(document)
stderr_thread = self.start_stderr_thread(p)
stderr_thread = self.start_stderr_thread(p, stderr)
if platform.system() != "Windows":
assert os.getpgid(p.pid) != os.getpgid(
@ -357,7 +357,7 @@ class IsolationProvider(ABC):
# Wait for the thread to complete. If it's still alive, mention it in the debug log.
stderr_thread.join(timeout=1)
debug_bytes = self.stderr.getvalue()
debug_bytes = stderr.getvalue()
debug_log = read_debug_text(debug_bytes)[:MAX_CONVERSION_LOG_CHARS]
incomplete = "(incomplete)\n" if stderr_thread.is_alive() else ""
@ -371,14 +371,14 @@ class IsolationProvider(ABC):
)
def start_stderr_thread(
self, process: subprocess.Popen
self, process: subprocess.Popen, stderr: IO[bytes]
) -> Optional[threading.Thread]:
"""Start a thread to read stderr from the process"""
def _stream_stderr(process_stderr: IO[bytes]) -> None:
try:
for line in process_stderr:
self.stderr.write(line)
stderr.write(line)
except (ValueError, IOError) as e:
log.debug(f"Stderr stream closed: {e}")

View file

@ -154,7 +154,7 @@ class Container(IsolationProvider):
args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stderr=self.proc_stderr,
startupinfo=startupinfo,
# Start the conversion process in a new session, so that we can later on
# kill the process group, without killing the controlling script.

View file

@ -1,7 +1,6 @@
import concurrent.futures
import json
import logging
from io import StringIO
from typing import Callable, List, Optional
import colorama