Reference: aspectlib.debug
¶
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. |
-
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=(<type 'exceptions.IOError'>, <type 'exceptions.OSError'>, <type 'exceptions.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!