This repository was archived by the owner on Nov 23, 2017. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -329,7 +329,13 @@ def wait(self):
329
329
self ._waiters .remove (fut )
330
330
331
331
finally :
332
- yield from self .acquire ()
332
+ # Must reacquire lock even if wait is cancelled
333
+ while True :
334
+ try :
335
+ yield from self .acquire ()
336
+ break
337
+ except futures .CancelledError :
338
+ pass
333
339
334
340
@coroutine
335
341
def wait_for (self , predicate ):
Original file line number Diff line number Diff line change @@ -457,6 +457,31 @@ def test_wait_cancel(self):
457
457
self .assertFalse (cond ._waiters )
458
458
self .assertTrue (cond .locked ())
459
459
460
+ def test_wait_cancel_contested (self ):
461
+ cond = asyncio .Condition (loop = self .loop )
462
+
463
+ self .loop .run_until_complete (cond .acquire ())
464
+ self .assertTrue (cond .locked ())
465
+
466
+ wait_task = asyncio .Task (cond .wait (), loop = self .loop )
467
+ test_utils .run_briefly (self .loop )
468
+ self .assertFalse (cond .locked ())
469
+
470
+ # Notify, but contest the lock before cancelling
471
+ self .loop .run_until_complete (cond .acquire ())
472
+ self .assertTrue (cond .locked ())
473
+ cond .notify ()
474
+ self .loop .call_soon (wait_task .cancel )
475
+ self .loop .call_soon (cond .release )
476
+
477
+ try :
478
+ self .loop .run_until_complete (wait_task )
479
+ except asyncio .CancelledError :
480
+ # Should not happen, since no cancellation points
481
+ pass
482
+
483
+ self .assertTrue (cond .locked ())
484
+
460
485
def test_wait_unacquired (self ):
461
486
cond = asyncio .Condition (loop = self .loop )
462
487
self .assertRaises (
You can’t perform that action at this time.
0 commit comments