From e204cc74226b02c83e343408551a97b4befafe18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 2 May 2019 15:07:13 +0200 Subject: [PATCH] Make event_handler_main shutdown gracefully on SIGTERM and SIGINT --- solvable/src/event_handler_main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/solvable/src/event_handler_main.py b/solvable/src/event_handler_main.py index 9ff99e5..a4f231a 100644 --- a/solvable/src/event_handler_main.py +++ b/solvable/src/event_handler_main.py @@ -1,9 +1,10 @@ from ast import literal_eval from functools import partial +from signal import signal, SIGTERM, SIGINT from tornado.ioloop import IOLoop -from tfw import YamlFSM, FSMAwareEventHandler +from tfw import YamlFSM, FSMAwareEventHandler, EventHandlerBase from tfw.components import IdeEventHandler, TerminalEventHandler from tfw.components import ProcessManagingEventHandler, BashMonitor from tfw.components import TerminalCommands, LogMonitoringEventHandler @@ -136,9 +137,12 @@ if __name__ == '__main__': # Example terminal command callback terminal.historymonitor.subscribe_callback(cenator) - try: - IOLoop.instance().start() - finally: - eventhandlers = {fsm, ide, terminal, processmanager, logmonitor, message_fsm_steps} - for eh in eventhandlers: + event_handlers = EventHandlerBase.get_local_instances() + def cleanup(sig, frame): + for eh in event_handlers: eh.cleanup() + exit(0) + signal(SIGTERM, cleanup) + signal(SIGINT, cleanup) + + IOLoop.instance().start()