mirror of
				https://github.com/avatao-content/test-tutorial-framework
				synced 2025-11-04 02:52:55 +00:00 
			
		
		
		
	Use new EventHandlerBase API to simplify graceful stop logic
This commit is contained in:
		@@ -165,10 +165,8 @@ def main():
 | 
			
		||||
        key='test'
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    event_handlers = EventHandler.get_local_instances()
 | 
			
		||||
    def stop(sig, frame):  # pylint: disable=unused-argument
 | 
			
		||||
        for eh in event_handlers:
 | 
			
		||||
            eh.stop()
 | 
			
		||||
    def stop(*_): 
 | 
			
		||||
        EventHandler.stop_all_instances()
 | 
			
		||||
        exit(0)
 | 
			
		||||
    signal(SIGTERM, stop)
 | 
			
		||||
    signal(SIGINT, stop)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ from signal import signal, SIGTERM, SIGINT
 | 
			
		||||
 | 
			
		||||
from tornado.ioloop import IOLoop
 | 
			
		||||
 | 
			
		||||
from tfw.event_handlers import EventHandlerBase
 | 
			
		||||
from tfw.builtins import EventHandler
 | 
			
		||||
from tfw.builtins import PipeIOEventHandler
 | 
			
		||||
from tfw.config import TFWENV
 | 
			
		||||
from tfw.logging import Log, Logger, LogFormatter, VerboseLogFormatter
 | 
			
		||||
@@ -19,23 +19,13 @@ from pipe_io_auxlib import (
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
def main():
 | 
			
		||||
    # pylint: disable=unused-variable
 | 
			
		||||
    Logger([
 | 
			
		||||
        Log(stderr, LogFormatter(20)),
 | 
			
		||||
        Log(TFWENV.LOGFILE, VerboseLogFormatter())
 | 
			
		||||
    ]).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(
 | 
			
		||||
        '',
 | 
			
		||||
        '/tmp/tfw_json_send',
 | 
			
		||||
@@ -77,12 +67,14 @@ if __name__ == '__main__':
 | 
			
		||||
        '/tmp/tfw_fsm_recv'
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    event_handlers = EventHandlerBase.get_local_instances()
 | 
			
		||||
    def stop(sig, frame):  # pylint: disable=unused-argument
 | 
			
		||||
        for eh in event_handlers:
 | 
			
		||||
            eh.stop()
 | 
			
		||||
    def stop(*_): 
 | 
			
		||||
        EventHandler.stop_all_instances()
 | 
			
		||||
        exit(0)
 | 
			
		||||
    signal(SIGTERM, stop)
 | 
			
		||||
    signal(SIGINT, stop)
 | 
			
		||||
 | 
			
		||||
    IOLoop.instance().start()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user