Skip to content

Commit 7c42e17

Browse files
committed
address review: bound snippet waits with timeouts
Assisted-by: Grok:4.6
1 parent 1860498 commit 7c42e17

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

‎extra_tests/snippets/stdlib_multiprocessing_condition.py‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def join_workers(workers):
1818
assert not worker.is_alive()
1919

2020

21+
def wait_sem(sem, msg):
22+
assert sem.acquire(timeout=5), msg
23+
24+
2125
def notify_all_six(ctx):
2226
cond = ctx.Condition()
2327
started = ctx.Semaphore(0)
@@ -35,15 +39,15 @@ def notify_all_six(ctx):
3539
thread.start()
3640
workers.append(thread)
3741

38-
for _ in range(6):
39-
started.acquire()
42+
for i in range(6):
43+
wait_sem(started, f"waiter {i} did not enter Condition.wait()")
4044

4145
cond.acquire()
4246
cond.notify_all()
4347
cond.release()
4448

45-
for _ in range(6):
46-
woken.acquire()
49+
for i in range(6):
50+
wait_sem(woken, f"waiter {i} did not wake")
4751
join_workers(workers)
4852

4953

@@ -59,18 +63,18 @@ def notify_one_then_the_other(ctx):
5963
thread.daemon = True
6064
thread.start()
6165

62-
started.acquire()
63-
started.acquire()
66+
wait_sem(started, "process did not enter Condition.wait()")
67+
wait_sem(started, "thread did not enter Condition.wait()")
6468

6569
cond.acquire()
6670
cond.notify()
6771
cond.release()
68-
woken.acquire()
72+
wait_sem(woken, "first waiter did not wake")
6973

7074
cond.acquire()
7175
cond.notify()
7276
cond.release()
73-
woken.acquire()
77+
wait_sem(woken, "second waiter did not wake")
7478
join_workers([proc, thread])
7579

7680

0 commit comments

Comments
 (0)