@@ -134,7 +134,7 @@ def __init__(self, client, path, identifier=None, extra_lock_patterns=()):
134
134
self ._retry = KazooRetry (
135
135
max_tries = None , sleep_func = client .handler .sleep_func
136
136
)
137
- self ._lock = client .handler .lock_object ()
137
+ self ._acquire_method_lock = client .handler .lock_object ()
138
138
139
139
def _ensure_path (self ):
140
140
self .client .ensure_path (self .path )
@@ -174,27 +174,17 @@ def acquire(self, blocking=True, timeout=None, ephemeral=True):
174
174
The ephemeral option.
175
175
"""
176
176
177
- def _acquire_lock ():
178
- got_it = self ._lock .acquire (False )
179
- if not got_it :
180
- raise ForceRetryError ()
181
- return True
182
-
183
177
retry = self ._retry .copy ()
184
178
retry .deadline = timeout
185
179
186
180
# Ensure we are locked so that we avoid multiple threads in
187
181
# 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 :
190
186
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
+
198
188
already_acquired = self .is_acquired
199
189
try :
200
190
gotten = False
@@ -220,7 +210,7 @@ def _acquire_lock():
220
210
self ._best_effort_cleanup ()
221
211
return gotten
222
212
finally :
223
- self ._lock .release ()
213
+ self ._acquire_method_lock .release ()
224
214
225
215
def _watch_session (self , state ):
226
216
self .wake_event .set ()
0 commit comments