diff --git a/solvable/src/event_handler_main.py b/solvable/src/event_handler_main.py index bbde28a..4a18323 100644 --- a/solvable/src/event_handler_main.py +++ b/solvable/src/event_handler_main.py @@ -1,12 +1,10 @@ import logging from sys import stderr from functools import partial -from signal import signal, SIGTERM, SIGINT from tornado.ioloop import IOLoop from tfw.fsm import YamlFSM -from tfw.builtins import EventHandler from tfw.builtins import IdeEventHandler, TerminalEventHandler, FrontendEventHandler from tfw.builtins import LogMonitoringEventHandler, ProcessManagingEventHandler from tfw.builtins import DirectorySnapshottingEventHandler, FSMManagingEventHandler @@ -16,6 +14,7 @@ from tao.config import TAOENV from custom_event_handlers import MessageFSMStepsEventHandler from custom_event_handlers import TerminalCallbackEventHandler, TestCommands +from signal_handling import setup_signal_handlers LOG = logging.getLogger(__name__) @@ -72,12 +71,7 @@ def main(): key='test' ) - def stop(*_): - EventHandler.stop_all_instances() - exit(0) - signal(SIGTERM, stop) - signal(SIGINT, stop) - + setup_signal_handlers() IOLoop.instance().start() diff --git a/solvable/src/pipe_io_main.py b/solvable/src/pipe_io_main.py index 1e9e26b..27d886f 100644 --- a/solvable/src/pipe_io_main.py +++ b/solvable/src/pipe_io_main.py @@ -1,10 +1,8 @@ import logging from sys import stderr -from signal import signal, SIGTERM, SIGINT from tornado.ioloop import IOLoop -from tfw.builtins import EventHandler from tfw.builtins import PipeIOEventHandler from tfw.config import TFWENV from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter @@ -15,6 +13,7 @@ from pipe_io_auxlib import ( DeployPipeIOEventHandler, IdePipeIOEventHandler, FSMPipeIOEventHandler ) +from signal_handling import setup_signal_handlers LOG = logging.getLogger(__name__) @@ -67,12 +66,7 @@ def main(): '/tmp/tfw_fsm_recv' ) - def stop(*_): - EventHandler.stop_all_instances() - exit(0) - signal(SIGTERM, stop) - signal(SIGINT, stop) - + setup_signal_handlers() IOLoop.instance().start() diff --git a/solvable/src/signal_handling.py b/solvable/src/signal_handling.py new file mode 100644 index 0000000..21294d2 --- /dev/null +++ b/solvable/src/signal_handling.py @@ -0,0 +1,11 @@ +from signal import signal, SIGTERM, SIGINT + +from tfw.builtins import EventHandler + + +def setup_signal_handlers(): + def stop(*_): + EventHandler.stop_all_instances() + exit(0) + signal(SIGTERM, stop) + signal(SIGINT, stop)