Compare commits

..

No commits in common. "f6a616f23b3323c640a461abee0a1b945e463d88" and "3a56f51e941738b27fcaf7474e2a22dc84b0fd06" have entirely different histories.

3 changed files with 8 additions and 7 deletions

View file

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

View file

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

View file

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