Skip to content

Commit

Permalink
simplify the way we retrieve the vents
Browse files Browse the repository at this point in the history
don't reassing the queue event. While I'm here log exception callbacks.
  • Loading branch information
benoitc committed Mar 1, 2013
1 parent e102937 commit c9df573
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions gaffer/events.py
Expand Up @@ -118,11 +118,15 @@
"""

from collections import deque
import logging

import pyuv

from .loop import patch_loop

LOGGER = logging.getLogger("gaffer")


class EventEmitter(object):
""" Many events happend in gaffer. For example a process will emist
the events "start", "stop", "exit".
Expand Down Expand Up @@ -231,15 +235,17 @@ def _dispatch_event(self):
self._spinner.start(lambda h: None)

def _send(self, handle):
queue, self._queue = self._queue, deque(maxlen=self._queue.maxlen)
wqueue, self._wqueue = self._wqueue, deque(maxlen=self._wqueue.maxlen)
lwqueue = len(self._wqueue)
lqueue = len(self._queue)

for evtype, args, kwargs in wqueue:
for i in range(lwqueue):
evtype, args, kwargs = self._wqueue.popleft()
if self._wildcards:
self._wildcards = self._send_listeners(evtype,
self._wildcards.copy(), *args, **kwargs)

for pattern, evtype, args, kwargs in queue:
for i in range(lqueue):
pattern, evtype, args, kwargs = self._queue.popleft()
# emit the event to all listeners
if pattern in self._events:
self._events[pattern] = self._send_listeners(evtype,
Expand All @@ -253,6 +259,8 @@ def _send_listeners(self, evtype, listeners, *args, **kwargs):
try:
listener(evtype, *args, **kwargs)
except Exception: # we ignore all exception
LOGGER.exception('exception calling listener callback for %r',
self)
to_remove.append(listener)

if once:
Expand Down

0 comments on commit c9df573

Please sign in to comment.