mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-17 02:31:50 +02:00
Compare commits
2 commits
3a56f51e94
...
f6a616f23b
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f6a616f23b | ||
![]() |
3b961e6b90 |
3 changed files with 7 additions and 8 deletions
|
@ -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}")
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import concurrent.futures
|
||||
import json
|
||||
import logging
|
||||
from io import StringIO
|
||||
from typing import Callable, List, Optional
|
||||
|
||||
import colorama
|
||||
|
|
Loading…
Reference in a new issue