mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-15 06:57:18 +00:00
Make cleanup() calls automatic in event_handler_main.py
This commit is contained in:
parent
829c244867
commit
3bda7bc540
@ -1,10 +1,12 @@
|
|||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from signal import signal, SIGTERM, SIGINT, SIGHUP
|
||||||
|
from sys import exit as sysexit
|
||||||
|
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
from tfw.fsm import YamlFSM
|
from tfw.fsm import YamlFSM
|
||||||
from tfw.event_handler_base import FSMAwareEventHandler
|
from tfw.event_handler_base import EventHandlerBase, FSMAwareEventHandler
|
||||||
from tfw.components import IdeEventHandler, TerminalEventHandler
|
from tfw.components import IdeEventHandler, TerminalEventHandler
|
||||||
from tfw.components import ProcessManagingEventHandler, BashMonitor
|
from tfw.components import ProcessManagingEventHandler, BashMonitor
|
||||||
from tfw.components import TerminalCommands, LogMonitoringEventHandler
|
from tfw.components import TerminalCommands, LogMonitoringEventHandler
|
||||||
@ -99,7 +101,9 @@ class MessageFSMStepsEventHandler(FSMAwareEventHandler):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main():
|
||||||
|
# pylint: disable=possibly-unused-variable
|
||||||
|
#
|
||||||
# TFW component EventHandlers (builtins, required for their respective functionalities)
|
# TFW component EventHandlers (builtins, required for their respective functionalities)
|
||||||
fsm = FSMManagingEventHandler( # TFW FSM
|
fsm = FSMManagingEventHandler( # TFW FSM
|
||||||
key='fsm',
|
key='fsm',
|
||||||
@ -131,20 +135,32 @@ if __name__ == '__main__':
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Your custom event handlers
|
# Your custom event handlers
|
||||||
message_fsm_steps = MessageFSMStepsEventHandler(
|
message_fsm_steps_eh = MessageFSMStepsEventHandler(
|
||||||
key='test'
|
key='test'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Terminal command handlers
|
# Terminal command handlers
|
||||||
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
|
commands = TestCommands(bashrc=f'/home/{TAOENV.USER}/.bashrc')
|
||||||
terminal.historymonitor.subscribe_callback(commands.callback)
|
terminal.historymonitor.subscribe_callback(commands.callback)
|
||||||
|
|
||||||
# Example terminal command callback
|
|
||||||
terminal.historymonitor.subscribe_callback(cenator)
|
terminal.historymonitor.subscribe_callback(cenator)
|
||||||
|
|
||||||
|
# Raise SystemExit on signals we should handle gracefully (make finally run)
|
||||||
|
trigger_finally = lambda a, b: sysexit()
|
||||||
|
signal(SIGTERM, trigger_finally)
|
||||||
|
signal(SIGINT, trigger_finally)
|
||||||
|
signal(SIGHUP, trigger_finally)
|
||||||
|
|
||||||
|
# Start event handlers and clean up on stopping
|
||||||
try:
|
try:
|
||||||
IOLoop.instance().start()
|
IOLoop.instance().start()
|
||||||
finally:
|
finally:
|
||||||
eventhandlers = {fsm, ide, terminal, processmanager, logmonitor, message_fsm_steps}
|
event_handlers = (
|
||||||
for eh in eventhandlers:
|
eh for eh in locals().values()
|
||||||
eh.cleanup()
|
if isinstance(eh, EventHandlerBase)
|
||||||
|
)
|
||||||
|
for event_handler in event_handlers:
|
||||||
|
event_handler.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user