1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 01:27:18 +00:00

Use new EventHandlerBase API to simplify graceful stop logic

This commit is contained in:
Kristóf Tóth 2019-07-01 16:02:44 +02:00
parent d263011179
commit 76118c0c49
2 changed files with 11 additions and 21 deletions

View File

@ -165,10 +165,8 @@ def main():
key='test' key='test'
) )
event_handlers = EventHandler.get_local_instances() def stop(*_):
def stop(sig, frame): # pylint: disable=unused-argument EventHandler.stop_all_instances()
for eh in event_handlers:
eh.stop()
exit(0) exit(0)
signal(SIGTERM, stop) signal(SIGTERM, stop)
signal(SIGINT, stop) signal(SIGINT, stop)

View File

@ -4,7 +4,7 @@ from signal import signal, SIGTERM, SIGINT
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
from tfw.event_handlers import EventHandlerBase from tfw.builtins import EventHandler
from tfw.builtins import PipeIOEventHandler from tfw.builtins import PipeIOEventHandler
from tfw.config import TFWENV from tfw.config import TFWENV
from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter
@ -19,23 +19,13 @@ from pipe_io_auxlib import (
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
if __name__ == '__main__': def main():
# pylint: disable=unused-variable
Logger([ Logger([
Log(stderr, LogFormatter(20)), Log(stderr, LogFormatter(20)),
Log(TFWENV.LOGFILE, VerboseLogFormatter()) Log(TFWENV.LOGFILE, VerboseLogFormatter())
]).start() ]).start()
"""
Creates general purpose pipes.
The first parameter associates the receiving pipe with a key, which is
an empty string in this case. It has a special meaning, you can
subscribe to every kind of message with this key.
If you wish to filter incoming data, specify a single or more keys in
a list, eg.: processmanager, ide, key...
You can send/receive JSON messages to/from the TFW server as any user,
because we gave read+write permissions, without that parameter, only
the owner has access to the pipes.
"""
json_pipe = PipeIOEventHandler( json_pipe = PipeIOEventHandler(
'', '',
'/tmp/tfw_json_send', '/tmp/tfw_json_send',
@ -77,12 +67,14 @@ if __name__ == '__main__':
'/tmp/tfw_fsm_recv' '/tmp/tfw_fsm_recv'
) )
event_handlers = EventHandlerBase.get_local_instances() def stop(*_):
def stop(sig, frame): # pylint: disable=unused-argument EventHandler.stop_all_instances()
for eh in event_handlers:
eh.stop()
exit(0) exit(0)
signal(SIGTERM, stop) signal(SIGTERM, stop)
signal(SIGINT, stop) signal(SIGINT, stop)
IOLoop.instance().start() IOLoop.instance().start()
if __name__ == '__main__':
main()