summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-07-20 15:18:57 -0400
committerKali Kaneko <kali@leap.se>2015-07-20 15:18:57 -0400
commitf508d3629686d1ad4574e5a7ec67f8b3283f7c5f (patch)
treeb78a6bc48a78a6ed914a3414f1734f315c92a53f
parent2cf0d452ca967114bb98d1d947c5ef5f7d19ccd1 (diff)
[refactor] remove use of reactor in threaded version of events client
the idea is that we'll be able to use the threaded version of the client, which makes use of the tornado ioloop, in a non-twisted module, like the main graphical client probably will be in the near future.
-rw-r--r--src/leap/common/events/client.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/leap/common/events/client.py b/src/leap/common/events/client.py
index 1a026ea..5ee617e 100644
--- a/src/leap/common/events/client.py
+++ b/src/leap/common/events/client.py
@@ -174,7 +174,8 @@ class EventsClient(object):
:type content: list
"""
logger.debug("Emitting event: (%s, %s)" % (event, content))
- self._send(str(event) + b'\0' + pickle.dumps(content))
+ payload = str(event) + b'\0' + pickle.dumps(content)
+ self._send(payload)
def _handle_event(self, event, content):
"""
@@ -186,7 +187,7 @@ class EventsClient(object):
:type content: list
"""
logger.debug("Handling event %s..." % event)
- for uid in self._callbacks[event].keys():
+ for uid in self._callbacks[event]:
callback = self._callbacks[event][uid]
logger.debug("Executing callback %s." % uid)
self._run_callback(callback, event, content)
@@ -398,8 +399,7 @@ class EventsClientThread(threading.Thread, EventsClient):
:param content: The content of the event.
:type content: list
"""
- from twisted.internet import reactor
- reactor.callFromThread(callback, event, *content)
+ self._loop.add_callback(lambda: callback(event, *content))
def register(self, event, callback, uid=None, replace=False):
"""
@@ -422,7 +422,8 @@ class EventsClientThread(threading.Thread, EventsClient):
callback identified by the given uid and replace is False.
"""
self.ensure_client()
- return EventsClient.register(self, event, callback, uid=uid, replace=replace)
+ return EventsClient.register(
+ self, event, callback, uid=uid, replace=replace)
def unregister(self, event, uid=None):
"""