mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Try to kill child processes of storage hook
This commit is contained in:
parent
5225e9d017
commit
1cbdda6c87
1 changed files with 7 additions and 0 deletions
|
@ -20,6 +20,7 @@ import contextlib
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shlex
|
import shlex
|
||||||
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from radicale import pathutils
|
from radicale import pathutils
|
||||||
|
@ -63,6 +64,7 @@ class StorageLockMixin:
|
||||||
# Use new process group for child to prevent terminals
|
# Use new process group for child to prevent terminals
|
||||||
# from sending SIGINT etc.
|
# from sending SIGINT etc.
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
|
# Process group is also used to identify child processes
|
||||||
popen_kwargs["preexec_fn"] = os.setpgrp
|
popen_kwargs["preexec_fn"] = os.setpgrp
|
||||||
elif os.name == "nt":
|
elif os.name == "nt":
|
||||||
popen_kwargs["creationflags"] = (
|
popen_kwargs["creationflags"] = (
|
||||||
|
@ -75,6 +77,11 @@ class StorageLockMixin:
|
||||||
except BaseException: # e.g. KeyboardInterrupt or SystemExit
|
except BaseException: # e.g. KeyboardInterrupt or SystemExit
|
||||||
p.kill()
|
p.kill()
|
||||||
raise
|
raise
|
||||||
|
finally:
|
||||||
|
if os.name == "posix":
|
||||||
|
# Try to kill child processes
|
||||||
|
with contextlib.suppress(OSError):
|
||||||
|
os.killpg(p.pid, signal.SIGKILL)
|
||||||
if stdout_data:
|
if stdout_data:
|
||||||
logger.debug("Captured stdout hook:\n%s", stdout_data)
|
logger.debug("Captured stdout hook:\n%s", stdout_data)
|
||||||
if stderr_data:
|
if stderr_data:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue