@@ -134,7 +134,7 @@ def __init__(self, client, path, identifier=None, extra_lock_patterns=()):
134134 self ._retry = KazooRetry (
135135 max_tries = None , sleep_func = client .handler .sleep_func
136136 )
137- self ._lock = client .handler .lock_object ()
137+ self ._acquire_method_lock = client .handler .lock_object ()
138138
139139 def _ensure_path (self ):
140140 self .client .ensure_path (self .path )
@@ -174,27 +174,17 @@ def acquire(self, blocking=True, timeout=None, ephemeral=True):
174174 The ephemeral option.
175175 """
176176
177- def _acquire_lock ():
178- got_it = self ._lock .acquire (False )
179- if not got_it :
180- raise ForceRetryError ()
181- return True
182-
183177 retry = self ._retry .copy ()
184178 retry .deadline = timeout
185179
186180 # Ensure we are locked so that we avoid multiple threads in
187181 # this acquistion routine at the same time...
188- locked = self ._lock .acquire (False )
189- if not locked and not blocking :
182+ method_locked = self ._acquire_method_lock .acquire (
183+ blocking = blocking , timeout = timeout if timeout is not None else - 1
184+ )
185+ if not method_locked :
190186 return False
191- if not locked :
192- # Lock acquire doesn't take a timeout, so simulate it...
193- # XXX: This is not true in Py3 >= 3.2
194- try :
195- locked = retry (_acquire_lock )
196- except RetryFailedError :
197- return False
187+
198188 already_acquired = self .is_acquired
199189 try :
200190 gotten = False
@@ -220,7 +210,7 @@ def _acquire_lock():
220210 self ._best_effort_cleanup ()
221211 return gotten
222212 finally :
223- self ._lock .release ()
213+ self ._acquire_method_lock .release ()
224214
225215 def _watch_session (self , state ):
226216 self .wake_event .set ()
0 commit comments