1
1
from gevent .hub import getcurrent
2
2
from gevent .lock import RLock as _RLock
3
3
4
+ import logging
5
+
4
6
from .exceptions import LockError
5
7
8
+ sentinel = object ()
6
9
7
10
class RLock (_RLock ):
8
11
def locked (self ):
@@ -22,16 +25,16 @@ class StrictLock:
22
25
timeout (int): Time in seconds acquisition will wait before raising an exception
23
26
"""
24
27
25
- def __init__ (self , timeout = 1 , name = None ):
28
+ def __init__ (self , timeout = None , name = None ):
26
29
self ._lock = RLock ()
27
30
self .timeout = timeout
28
31
self .name = name
29
32
30
33
def locked (self ):
31
34
return self ._lock .locked ()
32
35
33
- def acquire (self , blocking = True , timeout = None , _strict = True ):
34
- if not timeout :
36
+ def acquire (self , blocking = True , timeout = sentinel , _strict = True ):
37
+ if timeout is sentinel :
35
38
timeout = self .timeout
36
39
result = self ._lock .acquire (blocking , timeout = timeout )
37
40
if _strict and not result :
@@ -74,12 +77,12 @@ class CompositeLock:
74
77
timeout (int): Time in seconds acquisition will wait before raising an exception
75
78
"""
76
79
77
- def __init__ (self , locks , timeout = 1 ):
80
+ def __init__ (self , locks , timeout = None ):
78
81
self .locks = locks
79
82
self .timeout = timeout
80
83
81
- def acquire (self , blocking = True , timeout = None ):
82
- if not timeout :
84
+ def acquire (self , blocking = True , timeout = sentinel ):
85
+ if timeout is sentinel :
83
86
timeout = self .timeout
84
87
85
88
lock_all = all (
@@ -89,6 +92,7 @@ def acquire(self, blocking=True, timeout=None):
89
92
90
93
if not lock_all :
91
94
self ._emergency_release ()
95
+ logging .error (f"Unable to acquire { self } within { timeout } seconds" )
92
96
raise LockError ("ACQUIRE_ERROR" , self )
93
97
94
98
return True
0 commit comments