From dd04836896133441842f46acedef539a9eb54689 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 3 Jul 2017 11:34:33 +0200 Subject: [PATCH] Ignore SIGINT/TERM at kas level, let sub-processes handle it This seems to be the cleanest and simplest way of properly terminating kas while one or more sub-processes are running: just ignore the signal. The sub-processes will get it as well, and they will terminate themselves properly. kas will get an error then and shut down. Problem solved. Forwarding the signal didn't work reliably anyway because we couldn't count on kas being a process group leader in all cases. Signed-off-by: Jan Kiszka --- kas/kas.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kas/kas.py b/kas/kas.py index 47938fc..070b031 100644 --- a/kas/kas.py +++ b/kas/kas.py @@ -83,18 +83,15 @@ def create_logger(): def interruption(): """ - Handle SIGINT/SIGTERM + Ignore SIGINT/SIGTERM in kas, let them be handled by our sub-processes """ - sys.exit(1) + pass def _atexit_handler(): """ - Close event loop and terminate the whole process group + Wait for completion of the event loop """ - signal.signal(signal.SIGTERM, signal.SIG_IGN) - os.killpg(os.getpid(), signal.SIGTERM) - loop = asyncio.get_event_loop() pending = asyncio.Task.all_tasks() loop.run_until_complete(asyncio.gather(*pending))