aspectlib.contrib.retry | Decorator that retries the call retries times if func raises exceptions. |
aspectlib.contrib.retry.exponential_backoff | Wait 2**N seconds. |
aspectlib.contrib.retry.straight_backoff | Wait 1, 2, 5 seconds. |
aspectlib.contrib.retry.flat_backoff | Wait 1, 2, 5, 10, 15, 30 and 60 seconds. |
Wait 1, 2, 5, 10, 15, 30 and 60 seconds. All retries after the 5th retry will wait 60 seconds.
Decorator that retries the call retries times if func raises exceptions. Can use a backoff function to sleep till next retry.
Example
>>> should_fail = lambda foo=[1,2,3]: foo and foo.pop()
>>> @retry
... def flaky_func():
... if should_fail():
... raise OSError('Tough luck!')
... print("Success!")
...
>>> flaky_func()
Success!
If it reaches the retry limit:
>>> @retry
... def bad_func():
... raise OSError('Tough luck!')
...
>>> bad_func()
Traceback (most recent call last):
...
OSError: Tough luck!