Always start conversion process in new session

Start the conversion process in a new session, so that we can later on
kill the process group, without killing the controlling script (i.e.,
the Dangezone UI). This should not affect the conversion process in any
other way.
This commit is contained in:
Alex Pyrgiotis 2024-09-26 16:46:11 +03:00
parent 8d856ff4c3
commit b9a3dd63ad
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
5 changed files with 13 additions and 1 deletions

View file

@ -259,6 +259,11 @@ class IsolationProvider(ABC):
) -> 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."""
p = self.start_doc_to_pixels_proc(document) p = self.start_doc_to_pixels_proc(document)
if platform.system() != "Windows":
assert os.getpgid(p.pid) != os.getpgid(
os.getpid()
), "Parent shares same PGID with child"
try: try:
yield p yield p
except errors.ConverterProcException as e: except errors.ConverterProcException as e:

View file

@ -267,6 +267,9 @@ class Container(IsolationProvider):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=self.proc_stderr, stderr=self.proc_stderr,
startupinfo=startupinfo, 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.
start_new_session=True,
) )
def exec_container( def exec_container(

View file

@ -73,7 +73,7 @@ class Dummy(IsolationProvider):
pass pass
def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen: def start_doc_to_pixels_proc(self, document: Document) -> subprocess.Popen:
return subprocess.Popen("True") return subprocess.Popen("True", start_new_session=True)
def terminate_doc_to_pixels_proc( def terminate_doc_to_pixels_proc(
self, document: Document, p: subprocess.Popen self, document: Document, p: subprocess.Popen

View file

@ -67,6 +67,9 @@ class Qubes(IsolationProvider):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=stderr, stderr=stderr,
# Start the conversion process in a new session, so that we can later on
# kill the process group, without killing the controlling script.
start_new_session=True,
) )
if dev_mode: if dev_mode:

View file

@ -25,6 +25,7 @@ class DummyWait(Dummy):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
start_new_session=True,
) )
def terminate_doc_to_pixels_proc( def terminate_doc_to_pixels_proc(