Reretry is a Python library providing an easy-to-use, yet functional decorator for retrying functions on exceptions. It is a fork of the `retry` package, enhancing it with features like logging of traceback, callbacks after each failure, and support for `async` functions. Currently at version 0.11.8, it is actively maintained with a focus on providing a robust retry mechanism with minimal dependencies.
pip install reretryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates both synchronous and asynchronous usage of the `@retry` decorator. The `flaky_sync_function` will retry up to 3 times with a 1-second delay on `ValueError`, while `flaky_async_function` retries twice with a 0.5-second delay on `RuntimeError`. The `asyncio.run()` is used to execute the asynchronous example.
Upgrade to Python 3.7+ or use `pip install 'reretry<0.11.2'`.
Always set a finite `tries` parameter (e.g., `tries=5`) or a `max_delay` (e.g., `max_delay=60`) to prevent infinite retries, especially in production environments.
Review `reretry`'s documentation, especially the decorator parameters and their defaults, if migrating from the `retry` library.
Install the package using pip: `pip install reretry`.
Ensure the `exceptions` argument is set to catch the relevant exception type (e.g., `exceptions=(MyCustomError, ConnectionError)`) or use `exceptions=Exception` for a broad catch. Also, verify that the `tries` parameter is set to a sufficient number or is left at its default for infinite retries (though this is not recommended for production).
Upgrade `reretry` to version 0.11.0 or newer (`pip install --upgrade reretry`). Ensure your async function is correctly called and awaited within an `async` context or executed using `asyncio.run()`.