Improve log messages

This commit is contained in:
Unrud 2020-10-04 13:40:30 +02:00
parent b14889e170
commit c8b31637ef

View File

@ -70,21 +70,22 @@ class StorageLockMixin:
popen_kwargs["creationflags"] = ( popen_kwargs["creationflags"] = (
subprocess.CREATE_NEW_PROCESS_GROUP) subprocess.CREATE_NEW_PROCESS_GROUP)
command = hook % {"user": shlex.quote(user or "Anonymous")} command = hook % {"user": shlex.quote(user or "Anonymous")}
logger.debug("Running hook") logger.debug("Running storage hook")
p = subprocess.Popen(command, **popen_kwargs) p = subprocess.Popen(command, **popen_kwargs)
try: try:
stdout_data, stderr_data = p.communicate() stdout_data, stderr_data = p.communicate()
except BaseException: # e.g. KeyboardInterrupt or SystemExit except BaseException: # e.g. KeyboardInterrupt or SystemExit
p.kill() p.kill()
p.wait()
raise raise
finally: finally:
if os.name == "posix": if os.name == "posix":
# Try to kill child processes # Kill remaining children identified by process group
with contextlib.suppress(OSError): with contextlib.suppress(OSError):
os.killpg(p.pid, signal.SIGKILL) 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 from hook:\n%s", stdout_data)
if stderr_data: if stderr_data:
logger.debug("Captured stderr hook:\n%s", stderr_data) logger.debug("Captured stderr from hook:\n%s", stderr_data)
if p.returncode != 0: if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, p.args) raise subprocess.CalledProcessError(p.returncode, p.args)