Skip to content

Commit

Permalink
Try to kill child processes of storage hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Unrud committed Aug 31, 2020
1 parent 1e011e7 commit 2851525
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions radicale/storage/multifilesystem/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import os
import shlex
import signal
import subprocess

from radicale import pathutils
Expand Down Expand Up @@ -63,6 +64,7 @@ def acquire_lock(self, mode, user=None):
# Use new process group for child to prevent terminals
# from sending SIGINT etc.
if os.name == "posix":
# Process group is also used to identify child processes
popen_kwargs["preexec_fn"] = os.setpgrp
elif os.name == "nt":
popen_kwargs["creationflags"] = (
Expand All @@ -75,6 +77,11 @@ def acquire_lock(self, mode, user=None):
except BaseException: # e.g. KeyboardInterrupt or SystemExit
p.kill()
raise
finally:
if os.name == "posix":
# Try to kill child processes
with contextlib.suppress(OSError):
os.killpg(p.pid, signal.SIGKILL)
if stdout_data:
logger.debug("Captured stdout hook:\n%s", stdout_data)
if stderr_data:
Expand Down

0 comments on commit 2851525

Please sign in to comment.