File tree 3 files changed +24
-0
lines changed
3 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -354,6 +354,7 @@ def lock(
354
354
name : KeyT ,
355
355
timeout : Optional [float ] = None ,
356
356
sleep : float = 0.1 ,
357
+ blocking : bool = True ,
357
358
blocking_timeout : Optional [float ] = None ,
358
359
lock_class : Optional [Type [Lock ]] = None ,
359
360
thread_local : bool = True ,
@@ -369,6 +370,12 @@ def lock(
369
370
when the lock is in blocking mode and another client is currently
370
371
holding the lock.
371
372
373
+ ``blocking`` indicates whether calling ``acquire`` should block until
374
+ the lock has been acquired or to fail immediately, causing ``acquire``
375
+ to return False and the lock not being acquired. Defaults to True.
376
+ Note this value can be overridden by passing a ``blocking``
377
+ argument to ``acquire``.
378
+
372
379
``blocking_timeout`` indicates the maximum amount of time in seconds to
373
380
spend trying to acquire the lock. A value of ``None`` indicates
374
381
continue trying forever. ``blocking_timeout`` can be specified as a
@@ -411,6 +418,7 @@ def lock(
411
418
name ,
412
419
timeout = timeout ,
413
420
sleep = sleep ,
421
+ blocking = blocking ,
414
422
blocking_timeout = blocking_timeout ,
415
423
thread_local = thread_local ,
416
424
)
Original file line number Diff line number Diff line change @@ -801,6 +801,7 @@ def lock(
801
801
name : KeyT ,
802
802
timeout : Optional [float ] = None ,
803
803
sleep : float = 0.1 ,
804
+ blocking : bool = True ,
804
805
blocking_timeout : Optional [float ] = None ,
805
806
lock_class : Optional [Type [Lock ]] = None ,
806
807
thread_local : bool = True ,
@@ -816,6 +817,12 @@ def lock(
816
817
when the lock is in blocking mode and another client is currently
817
818
holding the lock.
818
819
820
+ ``blocking`` indicates whether calling ``acquire`` should block until
821
+ the lock has been acquired or to fail immediately, causing ``acquire``
822
+ to return False and the lock not being acquired. Defaults to True.
823
+ Note this value can be overridden by passing a ``blocking``
824
+ argument to ``acquire``.
825
+
819
826
``blocking_timeout`` indicates the maximum amount of time in seconds to
820
827
spend trying to acquire the lock. A value of ``None`` indicates
821
828
continue trying forever. ``blocking_timeout`` can be specified as a
@@ -858,6 +865,7 @@ def lock(
858
865
name ,
859
866
timeout = timeout ,
860
867
sleep = sleep ,
868
+ blocking = blocking ,
861
869
blocking_timeout = blocking_timeout ,
862
870
thread_local = thread_local ,
863
871
)
Original file line number Diff line number Diff line change @@ -97,6 +97,14 @@ async def test_float_timeout(self, r):
97
97
assert 8 < (await r .pttl ("foo" )) <= 9500
98
98
await lock .release ()
99
99
100
+ async def test_blocking (self , r ):
101
+ blocking = False
102
+ lock = self .get_lock (r , "foo" , blocking = blocking )
103
+ assert not lock .blocking
104
+
105
+ lock_2 = self .get_lock (r , "foo" )
106
+ assert lock_2 .blocking
107
+
100
108
async def test_blocking_timeout (self , r , event_loop ):
101
109
lock1 = self .get_lock (r , "foo" )
102
110
assert await lock1 .acquire (blocking = False )
You can’t perform that action at this time.
0 commit comments