Reference: aspectlib.debug
¶
Decorator that retries the call |
|
|
Wait 2**N seconds. |
|
Wait 1, 2, 5 seconds. |
|
Wait 1, 2, 5, 10, 15, 30 and 60 seconds. |
- aspectlib.contrib.flat_backoff(count)[source]¶
Wait 1, 2, 5, 10, 15, 30 and 60 seconds. All retries after the 5th retry will wait 60 seconds.
- aspectlib.contrib.retry(func=None, retries=5, backoff=None, exceptions=(<class 'OSError'>, <class 'OSError'>, <class 'EOFError'>), cleanup=None, sleep=<built-in function sleep>)[source]¶
Decorator that retries the call
retries
times iffunc
raisesexceptions
. Can use abackoff
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!