mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 06:21:31 +00:00
Don't store event_handler_function in EventHandlerBase
This commit is contained in:
parent
62a12c605c
commit
6a5b83f406
@ -6,7 +6,8 @@ from event_handler_base import EventHandlerBase
|
||||
|
||||
class EventHandler(EventHandlerBase):
|
||||
def __init__(self, anchor, event_handler_function, zmq_context=None):
|
||||
super().__init__(anchor, event_handler_function, zmq_context)
|
||||
super().__init__(anchor, zmq_context)
|
||||
self.event_handler_function = event_handler_function
|
||||
|
||||
def wrapper(msg_parts, handler):
|
||||
anchor, message = msg_parts
|
||||
|
@ -9,9 +9,8 @@ ioloop.install()
|
||||
|
||||
|
||||
class EventHandlerBase:
|
||||
def __init__(self, anchor, event_handler_function, zmq_context=None):
|
||||
def __init__(self, anchor, zmq_context=None):
|
||||
self.anchor = anchor
|
||||
self.event_handler_function = event_handler_function
|
||||
self.zmq_context = zmq_context or zmq.Context.instance()
|
||||
self.zmq_sub_socket = self.zmq_context.socket(zmq.SUB)
|
||||
self.subscriptions = {self.anchor}
|
||||
@ -33,7 +32,9 @@ class EventHandlerBase:
|
||||
def subscribe(self, anchor):
|
||||
if anchor not in self.subscriptions:
|
||||
self.subscriptions.add(anchor)
|
||||
self.zmq_sub_socket.setsockopt_string(zmq.SUBSCRIBE, anchor)
|
||||
self.zmq_sub_socket.setsockopt_string(
|
||||
zmq.SUBSCRIBE, anchor
|
||||
)
|
||||
|
||||
def unsubscribe(self, anchor):
|
||||
try:
|
||||
|
@ -7,8 +7,9 @@ from event_handler_base import EventHandlerBase
|
||||
|
||||
|
||||
class StatefulEventHandler(EventHandlerBase):
|
||||
def __init__(self, anchor, event_handler, zmq_context=None):
|
||||
super().__init__(anchor, event_handler, zmq_context)
|
||||
def __init__(self, anchor, event_handler_function, zmq_context=None):
|
||||
super().__init__(anchor, zmq_context)
|
||||
self.event_handler_function = event_handler_function
|
||||
self.generator = None
|
||||
self.subscribe('reset')
|
||||
|
||||
@ -36,4 +37,4 @@ class StatefulEventHandler(EventHandlerBase):
|
||||
response = [r.encode('utf-8') for r in (response_anchor, response_data)]
|
||||
self.zmq_push_socket.send_multipart(response)
|
||||
|
||||
self.zmq_sub_stream.on_recv(partial(wrapper, handler=event_handler))
|
||||
self.zmq_sub_stream.on_recv(partial(wrapper, handler=event_handler_function))
|
||||
|
Loading…
Reference in New Issue
Block a user