Skip to content

Commit

Permalink
make sure we trigger all events.
Browse files Browse the repository at this point in the history
following @saghul idea, start the spinner, pass it a dummy callback (lambda h:
None) and stop it at the end of _send. This will prevent the loop from
blocking for i/o on a given iteration if there are pending events, that is,
until the prepare handle is run. Als unref the prepare handle to not block the
loop.
  • Loading branch information
benoitc committed Mar 1, 2013
1 parent 26bd249 commit e102937
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gaffer/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def __init__(self, loop, max_size=200):
self._wqueue = deque(maxlen=max_size)

self._event_dispatcher = pyuv.Prepare(self.loop)
self._event_dispatcher.start(self._send)
self._event_dispatcher.unref()

self._spinner = pyuv.Idle(self.loop)

def close(self):
Expand Down Expand Up @@ -225,9 +228,7 @@ def unsubscribe_all(self, events=[]):
### private methods

def _dispatch_event(self):
if not self._event_dispatcher.active:
self._event_dispatcher.start(self._send)
self._spinner.start(lambda h: h.stop())
self._spinner.start(lambda h: None)

def _send(self, handle):
queue, self._queue = self._queue, deque(maxlen=self._queue.maxlen)
Expand All @@ -244,7 +245,7 @@ def _send(self, handle):
self._events[pattern] = self._send_listeners(evtype,
self._events[pattern].copy(), *args, **kwargs)

self._event_dispatcher.stop()
self._spinner.stop()

def _send_listeners(self, evtype, listeners, *args, **kwargs):
to_remove = []
Expand Down

0 comments on commit e102937

Please sign in to comment.