Permalink
Browse files

Autocreate path in ZooLock

  • Loading branch information...
1 parent 3289027 commit 89043d5d5ac8d10bd5d0ec677a853e2978deecc4 @labisso labisso committed Feb 24, 2012
Showing with 11 additions and 1 deletion.
  1. +11 −0 kazoo/recipe/lock.py
  2. +0 −1 kazoo/recipe/test/test_lock.py
View
@@ -32,6 +32,8 @@ def __init__(self, client, path, contender_name=None):
self.is_acquired = False
+ self.assured_path = False
+
def acquire(self):
"""Acquire the mutex, blocking until it is obtained
"""
@@ -47,6 +49,11 @@ def acquire(self):
raise
def _inner_acquire(self):
+
+ # make sure our election parent node exists
+ if not self.assured_path:
+ self.client.ensure_path(self.path)
+
node = None
if self.create_tried:
node = self._find_node()
@@ -131,6 +138,10 @@ def _inner_release(self):
def get_contenders(self):
"""Return an ordered list of the current contenders for the lock
"""
+ # make sure our election parent node exists
+ if not self.assured_path:
+ self.client.ensure_path(self.path)
+
children = self._get_sorted_children()
contenders = []
@@ -12,7 +12,6 @@ def setUp(self):
self._c = get_client_or_skip()
self._c.connect()
self.lockpath = "/" + uuid.uuid4().hex
- self._c.create(self.lockpath, "")
self.condition = threading.Condition()
self.active_thread = None

0 comments on commit 89043d5

Please sign in to comment.