wait-for

raw JSON →
1.2.0 verified Fri May 01 auth: no python

A waiting utility with decorator and logger support, providing configurable retries, timeouts, and custom conditions. Current version 1.2.0. Release cadence: irregular (last release Oct 2020). Supports Python >=3.6.

pip install wait-for
error TypeError: 'float' object cannot be interpreted as an integer
cause Passing a float timeout value before version 1.1.0; older versions expected integer.
fix
Update to wait-for 1.1.0+ (explicit float conversion) or ensure timeout is an integer.
error ImportError: cannot import name 'wait_for' from 'wait_for'
cause Incorrect installation or missing package (typo in package name: wait-for vs wait_for).
fix
Install the correct package: pip install wait-for (note the hyphen).
error wait_for() missing 1 required positional argument: 'func'
cause Calling `wait_for()` without a callable (the function to wait for).
fix
Pass a callable as the first argument: wait_for(my_func, timeout=10).
gotcha If `check_condition` raises an exception, `wait_for` retries by default (silent_failure=False). To avoid infinite retries on errors, set `silent_failure=True` or catch exceptions inside the condition.
fix Set `silent_failure=True` in the call to ignore exceptions and treat them as failures.
gotcha The `num_sec` argument for `delay` is explicitly converted to `float`. Passing a string or non-numeric type will raise a `TypeError`.
fix Always pass a number (int/float) for `delay` and `timeout`.
deprecated Python 2.7, 3.3, and 3.4 support was dropped in version 1.1.0. Using with these versions will fail.
fix Upgrade to Python 3.6+.

Waits for a condition to be true, retrying every `delay` seconds until `timeout`. Returns (result, elapsed_time) on success, raises TimedOutError on timeout.

from wait_for import wait_for
import time

def check_condition():
    # Replace with actual condition logic
    return False

try:
    result, elapsed = wait_for(check_condition, timeout=10, delay=1)
    print('Success', result, elapsed)
except Exception as e:
    print('Failed:', e)