mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 14:12:55 +00:00 
			
		
		
		
	Fix EventHandler subscriptions being registered several times
This commit is contained in:
		@@ -1,5 +1,4 @@
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
import tornado
 | 
			
		||||
import zmq
 | 
			
		||||
from tornado.web import Application
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,10 @@ from transitions import Machine
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FSMBase:
 | 
			
		||||
    states, transitions, message_handlers = [], [], []
 | 
			
		||||
    states, transitions = [], []
 | 
			
		||||
 | 
			
		||||
    def __init__(self, initial: str = None):
 | 
			
		||||
        self.message_handlers = []
 | 
			
		||||
        self.machine = Machine(model=self,
 | 
			
		||||
                               states=self.states,
 | 
			
		||||
                               transitions=self.transitions,
 | 
			
		||||
 
 | 
			
		||||
@@ -8,9 +8,11 @@ log = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ZMQWebSocketHandler(WebSocketHandler):
 | 
			
		||||
    _event_handler_connector = EventHandlerConnector()  #<--------------------. TODO: how is __init__()
 | 
			
		||||
                                                        # fix: made it static | TODO: called more than once?
 | 
			
		||||
    def __init__(self, application, request, **kwargs): #---------------------'
 | 
			
		||||
    _event_handler_connector = EventHandlerConnector() #----.
 | 
			
		||||
    # TODO: investigate thread safety!    <-----------------'
 | 
			
		||||
    # ZMQ sockets shared between several WebSocketHandler instances
 | 
			
		||||
    # http://pyzmq.readthedocs.io/en/latest/morethanbindings.html#thread-safety
 | 
			
		||||
    def __init__(self, application, request, **kwargs):
 | 
			
		||||
        super().__init__(application, request, **kwargs)
 | 
			
		||||
 | 
			
		||||
    def open(self, *args, **kwargs):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user