cond_waiter¶
Timeout-aware condition variable waiting.
This module provides CondWaiter, a small object holding a timeout and a time source, used to wait on condition variables with a consistent remaining-time semantics across multiple waits - which is needed by the components supporting custom TimeGen objects (like the executors).
CondWaiter
¶
A condition variable waiter holding a timeout and a time source.
Each wait() call consumes the remaining time held by the object, so that a sequence of waits honors a single overall timeout.
Example
import threading
waiter = cond_waiter.CondWaiter(timeout=10.0)
cond = threading.Condition()
with cond:
notified = waiter.wait(cond) # notified within the 10s budget?
Source code in py_misc_utils/cond_waiter.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 | |
wait(cond)
¶
Waits on a condition variable until notified - or timeout expiry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cond
|
The condition variable to wait on. The caller must hold its lock. |
required |
Returns:
| Type | Description |
|---|---|
|
True if the condition variable has been notified, False if the |
|
|
remaining wait time expired. |
Source code in py_misc_utils/cond_waiter.py
40 41 42 43 44 45 46 47 48 49 50 51 | |