From 4e2ae9c7e879094a61f6bb26281804ec857944ad Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 31 Aug 2014 01:58:14 -0700 Subject: Do the watch connected checking in the fire method --- zake/fake_client.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/zake/fake_client.py b/zake/fake_client.py index 2a97dff..f4dc75c 100644 --- a/zake/fake_client.py +++ b/zake/fake_client.py @@ -349,23 +349,22 @@ class FakeClient(object): self._listeners.discard(listener) def fire_child_watches(self, child_watches): - if not self._connected: - return for (paths, event) in child_watches: self._fire_watches(paths, event, self._child_watches) def fire_data_watches(self, data_watches): - if not self._connected: - return for (paths, event) in data_watches: self._fire_watches(paths, event, self._data_watches) def _fire_watches(self, paths, event, watch_source): for path in reversed(sorted(paths)): - with self._watches_lock: - watches = list(watch_source.pop(path, [])) - for w in watches: - self.handler.dispatch_callback(utils.make_cb(w, [event])) + with self._open_close_lock: + if self._connected: + with self._watches_lock: + watches = list(watch_source.pop(path, [])) + for w in watches: + cb = utils.make_cb(w, [event]) + self.handler.dispatch_callback(cb) def transaction(self): return FakeTransactionRequest(self) -- cgit v1.2.1