mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-05-11 07:51:49 +02:00
Compare commits
2 commits
caf4ce938f
...
7a479aa6f8
Author | SHA1 | Date | |
---|---|---|---|
7a479aa6f8 | |||
![]() |
4f4c523450 |
3 changed files with 10 additions and 17 deletions
|
@ -46,7 +46,8 @@ def print_header(s: str) -> None:
|
|||
"--debug",
|
||||
"debug",
|
||||
flag_value=True,
|
||||
help="Run Dangerzone in debug mode, to get logs from gVisor.")
|
||||
help="Run Dangerzone in debug mode, to get logs from gVisor.",
|
||||
)
|
||||
@click.version_option(version=get_version(), message="%(version)s")
|
||||
@errors.handle_document_errors
|
||||
def cli_main(
|
||||
|
|
|
@ -6,8 +6,8 @@ import signal
|
|||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
from queue import Queue
|
||||
from abc import ABC, abstractmethod
|
||||
from queue import Queue
|
||||
from typing import IO, Callable, Iterator, Optional
|
||||
|
||||
import fitz
|
||||
|
@ -94,7 +94,7 @@ class IsolationProvider(ABC):
|
|||
self.proc_stderr = subprocess.PIPE
|
||||
else:
|
||||
self.proc_stderr = subprocess.DEVNULL
|
||||
self.stderr_queue = Queue()
|
||||
self.stderr_queue: Queue = Queue()
|
||||
|
||||
def should_capture_stderr(self) -> bool:
|
||||
return self.debug or getattr(sys, "dangerzone_dev", False)
|
||||
|
@ -367,7 +367,7 @@ class IsolationProvider(ABC):
|
|||
f"{DOC_TO_PIXELS_LOG_END}"
|
||||
)
|
||||
|
||||
def _stream_stderr(self, stderr, queue: Queue) -> None:
|
||||
def _stream_stderr(self, stderr: IO[bytes], queue: Queue) -> None:
|
||||
"""Read stderr in a separate thread to avoid blocking"""
|
||||
try:
|
||||
for line in stderr:
|
||||
|
@ -383,6 +383,6 @@ class IsolationProvider(ABC):
|
|||
stderr_thread = threading.Thread(
|
||||
target=self._stream_stderr,
|
||||
args=(process.stderr, self.stderr_queue),
|
||||
daemon=True
|
||||
daemon=True,
|
||||
)
|
||||
stderr_thread.start()
|
||||
|
|
|
@ -154,7 +154,7 @@ class Container(IsolationProvider):
|
|||
args,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=self.proc_stderr,
|
||||
stderr=subprocess.PIPE,
|
||||
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.
|
||||
|
@ -192,18 +192,10 @@ class Container(IsolationProvider):
|
|||
args_str = " ".join(shlex.quote(s) for s in args)
|
||||
log.info("> " + args_str)
|
||||
|
||||
process = subprocess.Popen(
|
||||
args,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, # Always pipe stderr
|
||||
startupinfo=startupinfo,
|
||||
start_new_session=True,
|
||||
)
|
||||
|
||||
# Start stderr reader thread
|
||||
process = self.exec(args)
|
||||
# Start stderr reader thread, attaching it to the process
|
||||
self.start_stderr_thread(process)
|
||||
|
||||
|
||||
return process
|
||||
|
||||
def kill_container(self, name: str) -> None:
|
||||
|
|
Loading…
Reference in a new issue