multi_wait¶
Multi-threaded synchronization barrier with configurable signal count.
This module provides :class:MultiWait, a threading primitive that blocks
until a specified number of signals have been received. It is useful for
coordinating multiple worker threads that must all reach a checkpoint before
proceeding.
MultiWait
¶
A barrier waiting for a configurable number of signals before releasing.
Example
barrier = multi_wait.MultiWait(3) # released after 3 signal() calls
barrier.signal()
barrier.signal()
barrier.signal() # all threads waiting in barrier.wait() now proceed
Source code in py_misc_utils/multi_wait.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |
signal(n=1)
¶
Signal that n waiters have reached the barrier.
When the signal count reaches the configured count, all waiting threads are released.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
The number of signals to add (default: 1). |
1
|
Source code in py_misc_utils/multi_wait.py
33 34 35 36 37 38 39 40 41 42 43 44 45 | |
wait(timeout=None)
¶
Block until the signal count reaches the configured count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
Optional maximum time in seconds to wait. If None, wait indefinitely. |
None
|
Returns:
| Type | Description |
|---|---|
|
True if the barrier was released (signal count reached), False if the |
|
|
timeout elapsed first. |
Source code in py_misc_utils/multi_wait.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | |