我有websocket服务,用于打开流,接收消息等。我可以创建一个event_handler来打开新的连接,但不适用于将来的事件。这些将由新工作人员处理,那么如何与正在运行的工作人员/ greenthreads进行交互?
class ServiceA:
""" Event dispatching service. """
name = "service_a"
dispatch = EventDispatcher()
@rpc
def dispatching_method(self, payload):
self.dispatch("start_socket", payload)
class ServiceB:
""" Event listening service. """
name = "service_b"
@event_handler("service_a", "start_socket")
def start_socket(url):
sock = websocket.start_socket(url)
gr = eventlet.spawn(sock.run_forever)
调用sock
之后,如何与gr
中的ServiceA
或start_socket()
进行交互?