The 'waiting' library provides a simple utility for busy-waiting, where the program pauses execution until a specified predicate function returns `True`. It supports various modes, including timeouts, custom sleep intervals, exponential backoff, and aggregation of multiple predicates (ANY/ALL). The current version is 1.5.0, released in August 2024, with a sporadic but recently updated release cadence.
pip install waitingVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core `wait` function, showing how to wait for a predicate to become true, handling timeouts, and customizing polling intervals. It also highlights the benefit of the `waiting_for` argument for clearer error messages.
For asynchronous contexts, consider `asyncio.sleep()` or async-compatible polling libraries. If `waiting` must be used, run it in a separate thread or process to avoid blocking the main event loop.
Always use the `waiting_for` argument in `wait()` calls to provide a descriptive message. This message will be included in the `TimeoutExpired` exception, greatly aiding debugging. Example: `wait(predicate, timeout_seconds=..., waiting_for="database to be ready")`.
Ensure that predicates used with `ANY` or `ALL` are idempotent or that their side effects are not critical to occur on every single poll once satisfied. For predicates requiring continuous side effects, wrap them in a single predicate or handle side effects outside the predicate function.
Increase the `timeout_seconds` parameter or debug the `predicate` function to ensure the condition is eventually met.
Use `from waiting import wait` to import the function directly, or `import waiting` and then call `waiting.wait()`.
Call the `waiting.wait()` function directly, passing your predicate and other parameters as arguments.
No dependency data recorded yet.