Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cover one-by-one Condition.notify in the snippet
Wake a process waiter and a thread waiter with two notify()
calls, not only notify_all(), and keep the 20-repeat loop.

Assisted-by: Grok:4.6
  • Loading branch information
youknowone committed Sep 19, 2026
commit 1860498fe05e99b480d7327f25d003823ad54f1a
45 changes: 38 additions & 7 deletions extra_tests/snippets/stdlib_multiprocessing_condition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Thread+process Condition.notify_all must wake every waiter."""
"""Thread+process Condition notify must wake every waiter."""

import multiprocessing
import threading
Expand All @@ -12,8 +12,13 @@ def wait_on_condition(cond, started, woken):
cond.release()


def main():
ctx = multiprocessing.get_context("spawn")
def join_workers(workers):
for worker in workers:
worker.join(timeout=5)
assert not worker.is_alive()


def notify_all_six(ctx):
cond = ctx.Condition()
started = ctx.Semaphore(0)
woken = ctx.Semaphore(0)
Expand All @@ -39,14 +44,40 @@ def main():

for _ in range(6):
woken.acquire()
join_workers(workers)

for worker in workers:
worker.join(timeout=5)
assert not worker.is_alive()

def notify_one_then_the_other(ctx):
cond = ctx.Condition()
started = ctx.Semaphore(0)
woken = ctx.Semaphore(0)

proc = ctx.Process(target=wait_on_condition, args=(cond, started, woken))
proc.daemon = True
proc.start()
thread = threading.Thread(target=wait_on_condition, args=(cond, started, woken))
thread.daemon = True
thread.start()

started.acquire()
started.acquire()

cond.acquire()
cond.notify()
cond.release()
woken.acquire()

cond.acquire()
cond.notify()
cond.release()
woken.acquire()
join_workers([proc, thread])


if __name__ == "__main__":
multiprocessing.freeze_support()
ctx = multiprocessing.get_context("spawn")
# Enough repeats to surface a lost-wakeup race in CI snippets.
for _ in range(20):
main()
notify_all_six(ctx)
notify_one_then_the_other(ctx)
Loading