Skip to content

Commit

Permalink
BaseObserver: don't hold the lock while waiting on the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
kreichgauer committed Oct 21, 2011
1 parent ffa3751 commit 10d4795
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/watchdog/observers/api.py
Expand Up @@ -402,11 +402,17 @@ def on_thread_exit(self):
self.unschedule_all()

def _dispatch_event(self, event, watch):
for handler in self._get_handlers_for_watch(watch):
handler.dispatch(event)
with self._lock:
for handler in self._get_handlers_for_watch(watch):
handler.dispatch(event)

def dispatch_events(self, event_queue, timeout):
with self._lock:
event, watch = event_queue.get(block=True, timeout=timeout)
event, watch = event_queue.get(block=True, timeout=timeout)
try:
self._dispatch_event(event, watch)
event_queue.task_done()
except KeyError:
# All handlers for the watch have already been removed. We cannot
# lock properly here, because `event_queue.get` blocks whenever the
# queue is empty.
pass
event_queue.task_done()

0 comments on commit 10d4795

Please sign in to comment.