From 8244e22479365de0678aeec7a657bb0bbe57a3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 25 Jan 2018 15:24:42 +0100 Subject: [PATCH] Use fresh messaging instances for each event handler --- src/event_handlers/event_handler_base.py | 6 ++++-- src/event_handlers/event_handler_main.py | 10 +++++----- src/event_handlers/source_code_event_handler.py | 4 ++-- src/event_handlers/stateful_event_handler.py | 4 ++-- src/event_handlers/terminado_event_handler.py | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/event_handlers/event_handler_base.py b/src/event_handlers/event_handler_base.py index ac7d277..b8fee96 100644 --- a/src/event_handlers/event_handler_base.py +++ b/src/event_handlers/event_handler_base.py @@ -1,9 +1,11 @@ import json +from messaging import Messaging + class EventHandlerBase: - def __init__(self, messaging, anchor): - self.messaging = messaging + def __init__(self, anchor): + self.messaging = Messaging() self.anchor = anchor self.messaging.subscribe(self.anchor) self.subscriptions = {self.anchor} diff --git a/src/event_handlers/event_handler_main.py b/src/event_handlers/event_handler_main.py index 7373d67..1583cf3 100644 --- a/src/event_handlers/event_handler_main.py +++ b/src/event_handlers/event_handler_main.py @@ -85,10 +85,10 @@ class LoginHandler(EventHandlerBase): if __name__ == '__main__': messaging = Messaging() - anchor_a = ChangeCaseHandler(messaging, 'anchor_a') - anchor_b = Rot13Handler(messaging, 'anchor_b') - anchor_c = ReverseHandler(messaging, 'anchor_c') - anchor_webide = SourceCodeEventHandler(messaging, 'anchor_webide', 'login_component.py', 'login') - anchor_terminado = TerminadoEventHandler(messaging, 'anchor_terminado', 'terminado') + anchor_a = ChangeCaseHandler('anchor_a') + anchor_b = Rot13Handler('anchor_b') + anchor_c = ReverseHandler('anchor_c') + anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_component.py', 'login') + anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado') IOLoop.instance().start() diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 17c9007..78cd636 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -9,8 +9,8 @@ from event_handler_base import EventHandlerBase class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): - def __init__(self, messaging, anchor, filename, process_name=None): - super().__init__(messaging, anchor) + def __init__(self, anchor, filename, process_name=None): + super().__init__(anchor) self.working_directory = LOGIN_APP_DIR self.filename = filename self.language = map_file_extension_to_language(filename) diff --git a/src/event_handlers/stateful_event_handler.py b/src/event_handlers/stateful_event_handler.py index f76f510..d7bee13 100644 --- a/src/event_handlers/stateful_event_handler.py +++ b/src/event_handlers/stateful_event_handler.py @@ -4,8 +4,8 @@ from event_handler_base import EventHandlerBase class StatefulEventHandler(EventHandlerBase): - def __init__(self, messaging, anchor, event_handler_function): - super().__init__(messaging, anchor) + def __init__(self, anchor, event_handler_function): + super().__init__(anchor) self.event_handler_function = event_handler_function self.generator = None self.subscribe('reset') diff --git a/src/event_handlers/terminado_event_handler.py b/src/event_handlers/terminado_event_handler.py index 973c3d5..1ba2bfb 100644 --- a/src/event_handlers/terminado_event_handler.py +++ b/src/event_handlers/terminado_event_handler.py @@ -9,8 +9,8 @@ from config import TERMINADO_DIR class TerminadoEventHandler(EventHandlerBase, SupervisorMixin): - def __init__(self, messaging, anchor, process_name): - super().__init__(messaging, anchor) + def __init__(self, anchor, process_name): + super().__init__(anchor) self.working_directory = TERMINADO_DIR self.process_name = process_name self.setup_terminado_server()