11from gevent .hub import getcurrent
22from gevent .lock import RLock as _RLock
33
4+ import logging
5+
46from .exceptions import LockError
57
8+ sentinel = object ()
69
710class RLock (_RLock ):
811 def locked (self ):
@@ -22,16 +25,16 @@ class StrictLock:
2225 timeout (int): Time in seconds acquisition will wait before raising an exception
2326 """
2427
25- def __init__ (self , timeout = 1 , name = None ):
28+ def __init__ (self , timeout = None , name = None ):
2629 self ._lock = RLock ()
2730 self .timeout = timeout
2831 self .name = name
2932
3033 def locked (self ):
3134 return self ._lock .locked ()
3235
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 :
3538 timeout = self .timeout
3639 result = self ._lock .acquire (blocking , timeout = timeout )
3740 if _strict and not result :
@@ -74,12 +77,12 @@ class CompositeLock:
7477 timeout (int): Time in seconds acquisition will wait before raising an exception
7578 """
7679
77- def __init__ (self , locks , timeout = 1 ):
80+ def __init__ (self , locks , timeout = None ):
7881 self .locks = locks
7982 self .timeout = timeout
8083
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 :
8386 timeout = self .timeout
8487
8588 lock_all = all (
@@ -89,6 +92,7 @@ def acquire(self, blocking=True, timeout=None):
8992
9093 if not lock_all :
9194 self ._emergency_release ()
95+ logging .error (f"Unable to acquire { self } within { timeout } seconds" )
9296 raise LockError ("ACQUIRE_ERROR" , self )
9397
9498 return True
0 commit comments