From 7248d5e1bbfa004fefd0eab4ef9aac90203cc973 Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Wed, 28 Jun 2017 19:26:01 +0200 Subject: [PATCH] Fix termination steps Another, hopefully better attempt: Ignore the TERM signal in the sending process so that we can properly clean up all the futures before actually closing. This also avoids a "Terminated" message even on regular kas endings. Signed-off-by: Jan Kiszka --- kas/kas.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kas/kas.py b/kas/kas.py index 8d06a22..47938fc 100644 --- a/kas/kas.py +++ b/kas/kas.py @@ -92,9 +92,14 @@ def _atexit_handler(): """ Close event loop and terminate the whole process group """ - asyncio.get_event_loop().close() + 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)) + loop.close() + def kas_get_argparser(): """