summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2014-08-31 01:13:42 -0700
committerJoshua Harlow <harlowja@gmail.com>2014-08-31 01:14:53 -0700
commit4b1fc0f50c9fc0f9f866bfc79aeabd3d68f964e8 (patch)
tree3c318de47415afd5152dbcec0cc7350f12487c00
parent72caf3f354ff82c1905c9adcc1a3d7ce39737ea1 (diff)
downloadzake-4b1fc0f50c9fc0f9f866bfc79aeabd3d68f964e8.tar.gz
Avoid holding the open_close_lock while performing activities
Instead of holding the lock while doing further activities just release it and mark a variable that will determine if further work is done. This does leave the client open to simulatanous start/stop issues from multiple threads but this seems acceptable as only one thread should be using a client at a time anyway...
-rw-r--r--zake/fake_client.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/zake/fake_client.py b/zake/fake_client.py
index 5a2566e..09bd308 100644
--- a/zake/fake_client.py
+++ b/zake/fake_client.py
@@ -237,16 +237,19 @@ class FakeClient(object):
return utils.dispatch_async(self.handler, self.get, path, watch=watch)
def start(self, timeout=None):
+ started = False
with self._open_close_lock:
if not self._connected:
- with self._watches_lock:
- self._child_watches.clear()
- self._data_watches.clear()
self._connected = True
- self.storage.attach(self)
- self.handler.start()
- self._partial_client.session_id = int(uuid.uuid4())
- self._fire_state_change(k_states.KazooState.CONNECTED)
+ started = True
+ if started:
+ with self._watches_lock:
+ self._child_watches.clear()
+ self._data_watches.clear()
+ self.storage.attach(self)
+ self.handler.start()
+ self._partial_client.session_id = int(uuid.uuid4())
+ self._fire_state_change(k_states.KazooState.CONNECTED)
def restart(self):
with self._open_close_lock:
@@ -384,14 +387,17 @@ class FakeClient(object):
return utils.dispatch_async(self.handler, self.ensure_path, path)
def close(self, close_handler=True):
+ closed = False
with self._open_close_lock:
if self._connected:
self._connected = False
- self.storage.purge(self)
- self._fire_state_change(k_states.KazooState.LOST)
- if self._own_handler and close_handler:
- self.handler.stop()
- self._partial_client.session_id = None
+ closed = True
+ if closed:
+ self.storage.purge(self)
+ self._fire_state_change(k_states.KazooState.LOST)
+ if self._own_handler and close_handler:
+ self.handler.stop()
+ self._partial_client.session_id = None
class _PartialClient(object):