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