- Generic Decorator
- Specify stop condition (i.e. limit by number of attempts)
- Specify wait condition (i.e. exponential backoff sleeping between attempts)
- Customize retrying on Exceptions
Read the docs for further information.
Install using pip
:
pip install python-retry
>>> from python_retry import retry
>>> import pytest
>>>
>>> @retry()
... def div(num: int, den: int):
... return num/den
>>>
>>> div(1, 0)
>>> import logging
>>> logger = logging.getLogger("foo")
>>>
>>> @retry(
... retry_on=(ZeroDivisionError,),
... max_retries=2,
... backoff_factor=1,
... supress_exception=True,
... retry_logger=logger
... )
... def div(num: int, den: int):
... return num / den
>>>
>>> div(1, 0)
You can find here at Read the docs the complete documentation.