pyfunctools.decorators.retry_decorator module
- no-index:
- pyfunctools.decorators.retry_decorator.retry_decorator(retries=3, delay=2)[source]
A decorator to retry a function execution upon failure.
This decorator retries the execution of the decorated function a specified number of times, with a delay between each attempt, in case of an exception.
- Parameters:
retries (int) – The number of retry attempts. Default is 3.
delay (int) – The delay between retries in seconds. Default is 2.
- Returns:
A function that retries the original function upon failure.
- Return type:
callable
Example
>>> @retry_decorator(retries=5, delay=1) ... def flaky_function(): ... import random ... if random.choice([True, False]): ... raise ValueError("Oops, something went wrong!") ... return "Success!" >>> >>> print(flaky_function()) "Success!" # (or an exception after retries)