Skip to content

Commit

Permalink
FIXUP: Work with terminated process group
Browse files Browse the repository at this point in the history
  • Loading branch information
apyrgio committed Sep 23, 2024
1 parent 62cfdeb commit 75ca33d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dangerzone/isolation_provider/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,26 @@ def terminate_doc_to_pixels_proc(
"""Terminate gracefully the process started for the doc-to-pixels phase."""
pass

def _signal_process_group(self, p: subprocess.Popen, signo: int) -> None:
try:
os.killpg(os.getpgid(p.pid), signo)
except (ProcessLookupError, PermissionError):
# If the process no longer exists, we may encounter the above errors, either
# when looking for the process group (ProcessLookupError), or when trying to
# kill a process group that no longer exists (PermissionError)
return

def terminate_process_group(self, p: subprocess.Popen) -> None:
if platform.system() == "Windows":
p.terminate()
else:
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
self._signal_process_group(signal.SIGTERM)

def kill_process_group(self, p: subprocess.Popen) -> None:
if platform.system() == "Windows":
p.kill()
else:
os.killpg(os.getpgid(p.pid), signal.SIGKILL)
self._signal_process_group(signal.SIGKILL)

def ensure_stop_doc_to_pixels_proc(
self,
Expand Down

0 comments on commit 75ca33d

Please sign in to comment.