From 23cc381495651faf39235b1ea6ef843d4f207671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 31 Jan 2018 15:10:05 +0100 Subject: [PATCH] Fix EventHandler subscriptions being registered several times --- src/app/app.py | 1 - src/app/fsm_base.py | 3 ++- src/app/handlers/zmq_websocket_handler.py | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/app/app.py b/src/app/app.py index 0bc3fa1..0a33687 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -1,5 +1,4 @@ import sys - import tornado import zmq from tornado.web import Application diff --git a/src/app/fsm_base.py b/src/app/fsm_base.py index 415d359..6557733 100644 --- a/src/app/fsm_base.py +++ b/src/app/fsm_base.py @@ -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, diff --git a/src/app/handlers/zmq_websocket_handler.py b/src/app/handlers/zmq_websocket_handler.py index c65a955..3090712 100644 --- a/src/app/handlers/zmq_websocket_handler.py +++ b/src/app/handlers/zmq_websocket_handler.py @@ -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):