polling2 is an updated Python polling utility that provides many configurable options for retrying operations. It allows users to repeatedly call a function until a desired condition is met, handling timeouts, delays, and error logging. The current version is 0.5.0, with new features and minor fixes released periodically.
pip install polling2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `polling2.poll` to wait for a simulated resource to become available. It sets a target function, a polling interval (`step`), a maximum wait time (`timeout`), and a `check_success` function to define when polling should stop. It also includes error handling for `TimeoutException`.
Update `pip install` commands to `polling2` and change all import statements from `import polling` or `from polling import ...` to `import polling2` or `from polling2 import ...`.
For infinite polling, explicitly set `poll_forever=True`. For finite polling, always provide a positive integer for `timeout`. Avoid using `timeout=0` or `timeout=None` unless infinite polling is desired.
Ensure your `check_success` logic reliably returns `True` or `False`. If the `target` function might raise exceptions that should not immediately stop polling, use the `ignore_exceptions` parameter, e.g., `ignore_exceptions=(ConnectionError,)`.
Always wrap `poll()` calls in `try-except` blocks to gracefully handle `polling2.TimeoutException` and `polling2.MaxCallException`. This allows for proper error reporting or fallback logic.
Install the library using pip: `pip install polling2`
Catch the `polling2.TimeoutException` to handle the failure. You might need to increase the `timeout` or `max_tries` values, or refine your `target` or `check_success` logic.
Review the `polling2.poll()` documentation and ensure all keyword arguments (e.g., `target`, `step`, `timeout`, `check_success`, `ignore_exceptions`) are spelled correctly and are valid parameters for the function.
Ensure your `target` function eventually returns a value that satisfies your `check_success` condition (or is truthy by default). If `poll_forever` is not intended, set a `timeout` or `max_tries`. If using a lambda, ensure it calls the function, e.g., `lambda: my_function()` instead of `lambda: my_function` or `lambda: my_function == True` if `my_function` is meant to be executed.
No dependency data recorded yet.