{"id":7669,"library":"reretry","title":"Reretry","description":"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.","status":"active","version":"0.11.8","language":"en","source_language":"en","source_url":"https://github.com/leshchenko1979/reretry","tags":["retry","decorator","resilience","async","error handling"],"install":[{"cmd":"pip install reretry","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Optionally preserves function signatures, not strictly required for core functionality.","package":"decorator","optional":true}],"imports":[{"symbol":"retry","correct":"from reretry import retry"}],"quickstart":{"code":"import random\nimport asyncio\nfrom reretry import retry\n\nattempt_count = 0\n\n@retry(exceptions=ValueError, tries=3, delay=1)\ndef flaky_sync_function():\n    global attempt_count\n    attempt_count += 1\n    print(f\"Sync function attempt {attempt_count}...\")\n    if random.randint(1, 10) < 7:\n        raise ValueError(\"Sync operation failed!\")\n    print(\"Sync operation succeeded!\")\n    return \"Success\"\n\nasync_attempt_count = 0\n\n@retry(exceptions=RuntimeError, tries=2, delay=0.5)\nasync def flaky_async_function():\n    global async_attempt_count\n    async_attempt_count += 1\n    print(f\"Async function attempt {async_attempt_count}...\")\n    if random.randint(1, 10) < 8:\n        raise RuntimeError(\"Async operation failed!\")\n    print(\"Async operation succeeded!\")\n    return \"Async Success\"\n\nif __name__ == \"__main__\":\n    print(\"\\n--- Running Synchronous Example ---\")\n    try:\n        result_sync = flaky_sync_function()\n        print(f\"Final sync result: {result_sync}\")\n    except Exception as e:\n        print(f\"Sync function ultimately failed: {e}\")\n\n    print(\"\\n--- Running Asynchronous Example ---\")\n    try:\n        result_async = asyncio.run(flaky_async_function())\n        print(f\"Final async result: {result_async}\")\n    except Exception as e:\n        print(f\"Async function ultimately failed: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.7+ or use `pip install 'reretry<0.11.2'`.","message":"Python 3.5 support was dropped in `reretry` version 0.11.2. If you are using Python 3.5 or older, you must either upgrade your Python environment or pin `reretry` to a version older than 0.11.2.","severity":"breaking","affected_versions":">=0.11.2"},{"fix":"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.","message":"By default, the `@retry` decorator is configured with `tries=-1`, meaning it will attempt to retry indefinitely until the decorated function succeeds or another unhandled exception occurs. This can lead to hung processes if not explicitly controlled.","severity":"gotcha","affected_versions":"All"},{"fix":"Review `reretry`'s documentation, especially the decorator parameters and their defaults, if migrating from the `retry` library.","message":"Reretry is a fork of the `retry` package. While it aims to be mostly compatible, some differences in API, defaults, or available features might exist. Direct migration from the original `retry` library may require minor adjustments.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the package using pip: `pip install reretry`.","cause":"The `reretry` package is not installed in the current Python environment or the environment is not activated.","error":"ModuleNotFoundError: No module named 'reretry'"},{"fix":"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).","cause":"The `exceptions` argument in `@retry` is not catching the specific exception being raised, or the `tries` limit is too low and quickly exhausted.","error":"My decorated function isn't retrying; it just fails immediately."},{"fix":"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()`.","cause":"`reretry` introduced async function support in version 0.11.0. This error might occur if you are using an older version or if the async function is not properly awaited or run.","error":"My async function decorated with @retry is not working or is hanging."}]}