diff --git a/dangerzone/isolation_provider/base.py b/dangerzone/isolation_provider/base.py index e13d5e53a..019897689 100644 --- a/dangerzone/isolation_provider/base.py +++ b/dangerzone/isolation_provider/base.py @@ -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,