@@ -461,21 +461,28 @@ def _check_notify(self, cond):
461
461
# construct. In particular, it is possible that this can no longer
462
462
# be conveniently guaranteed should their implementation ever change.
463
463
N = 5
464
+ ready = []
464
465
results1 = []
465
466
results2 = []
466
467
phase_num = 0
467
468
def f ():
468
469
cond .acquire ()
470
+ ready .append (phase_num )
469
471
result = cond .wait ()
470
472
cond .release ()
471
473
results1 .append ((result , phase_num ))
472
474
cond .acquire ()
475
+ ready .append (phase_num )
473
476
result = cond .wait ()
474
477
cond .release ()
475
478
results2 .append ((result , phase_num ))
476
479
b = Bunch (f , N )
477
480
b .wait_for_started ()
478
- _wait ()
481
+ # first wait, to ensure all workers settle into cond.wait() before
482
+ # we continue. See issues #8799 and #30727.
483
+ while len (ready ) < 5 :
484
+ _wait ()
485
+ ready = []
479
486
self .assertEqual (results1 , [])
480
487
# Notify 3 threads at first
481
488
cond .acquire ()
@@ -487,9 +494,9 @@ def f():
487
494
_wait ()
488
495
self .assertEqual (results1 , [(True , 1 )] * 3 )
489
496
self .assertEqual (results2 , [])
490
- # first wait, to ensure all workers settle into cond.wait() before
491
- # we continue. See issue #8799
492
- _wait ()
497
+ # make sure all awaken workers settle into cond.wait()
498
+ while len ( ready ) < 3 :
499
+ _wait ()
493
500
# Notify 5 threads: they might be in their first or second wait
494
501
cond .acquire ()
495
502
cond .notify (5 )
@@ -500,7 +507,9 @@ def f():
500
507
_wait ()
501
508
self .assertEqual (results1 , [(True , 1 )] * 3 + [(True , 2 )] * 2 )
502
509
self .assertEqual (results2 , [(True , 2 )] * 3 )
503
- _wait () # make sure all workers settle into cond.wait()
510
+ # make sure all workers settle into cond.wait()
511
+ while len (ready ) < 5 :
512
+ _wait ()
504
513
# Notify all threads: they are all in their second wait
505
514
cond .acquire ()
506
515
cond .notify_all ()
0 commit comments