From 849fd7b61c46b90a5c11cfdba27fb5940f452a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 7 Feb 2018 10:13:06 +0100 Subject: [PATCH] Hotfix eventhandlers invoked several times. Waiting for server refactor. --- lib/tfw/fsm_base.py | 3 +++ lib/tfw/networking/server/zmq_websocket_handler.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/tfw/fsm_base.py b/lib/tfw/fsm_base.py index 6557733..d6a586c 100644 --- a/lib/tfw/fsm_base.py +++ b/lib/tfw/fsm_base.py @@ -21,3 +21,6 @@ class FSMBase: def subscribe_message_handler(self, msghandler): self.message_handlers.append(msghandler) + + def unsubscribe_message_handler(self, msghandler): + self.message_handlers.remove(msghandler) diff --git a/lib/tfw/networking/server/zmq_websocket_handler.py b/lib/tfw/networking/server/zmq_websocket_handler.py index e29304d..aa55382 100644 --- a/lib/tfw/networking/server/zmq_websocket_handler.py +++ b/lib/tfw/networking/server/zmq_websocket_handler.py @@ -49,6 +49,9 @@ class FSMManagingSocketHandler(ZMQWebSocketHandler): FSMManagingSocketHandler.fsm = FSM() self.fsm.subscribe_message_handler(self.handle_fsm_message) + def on_close(self): + self.fsm.unsubscribe_message_handler(self.handle_fsm_message) + def handle_fsm_message(self, message): self._event_handler_connector.send_message(message)