@@ -359,21 +359,28 @@ def _check_notify(self, cond):
359
359
# construct. In particular, it is possible that this can no longer
360
360
# be conveniently guaranteed should their implementation ever change.
361
361
N = 5
362
+ ready = []
362
363
results1 = []
363
364
results2 = []
364
365
phase_num = 0
365
366
def f ():
366
367
cond .acquire ()
368
+ ready .append (phase_num )
367
369
cond .wait ()
368
370
cond .release ()
369
371
results1 .append (phase_num )
370
372
cond .acquire ()
373
+ ready .append (phase_num )
371
374
cond .wait ()
372
375
cond .release ()
373
376
results2 .append (phase_num )
374
377
b = Bunch (f , N )
375
378
b .wait_for_started ()
376
- _wait ()
379
+ # first wait, to ensure all workers settle into cond.wait() before
380
+ # we continue. See issues #8799 and #30727.
381
+ while len (ready ) < 5 :
382
+ _wait ()
383
+ ready = []
377
384
self .assertEqual (results1 , [])
378
385
# Notify 3 threads at first
379
386
cond .acquire ()
@@ -385,9 +392,9 @@ def f():
385
392
_wait ()
386
393
self .assertEqual (results1 , [1 ] * 3 )
387
394
self .assertEqual (results2 , [])
388
- # first wait, to ensure all workers settle into cond.wait() before
389
- # we continue. See issue #8799
390
- _wait ()
395
+ # make sure all awaken workers settle into cond.wait()
396
+ while len ( ready ) < 3 :
397
+ _wait ()
391
398
# Notify 5 threads: they might be in their first or second wait
392
399
cond .acquire ()
393
400
cond .notify (5 )
@@ -398,7 +405,9 @@ def f():
398
405
_wait ()
399
406
self .assertEqual (results1 , [1 ] * 3 + [2 ] * 2 )
400
407
self .assertEqual (results2 , [2 ] * 3 )
401
- _wait () # make sure all workers settle into cond.wait()
408
+ # make sure all workers settle into cond.wait()
409
+ while len (ready ) < 5 :
410
+ _wait ()
402
411
# Notify all threads: they are all in their second wait
403
412
cond .acquire ()
404
413
cond .notify_all ()
0 commit comments