Created
October 9, 2014 16:48
-
-
Save j-griffith/1c1c668dde70c1e1b011 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def retry(exc, tries=5, delay=1, backoff=2): | |
def retry_dec(f): | |
@wraps(f) | |
def func_retry(*args, **kwargs): | |
_tries, _delay = tries, delay | |
while _tries > 1: | |
try: | |
return f(*args, **kwargs) | |
except Exception as ex: | |
time.sleep(_delay) | |
_tries -= 1 | |
_delay *= backoff | |
return f(*args, **kwargs) | |
return func_retry | |
return retry_dec | |
@retry((exception.A, exception.B), tries=5) | |
def myfunc(self,): | |
blah blah blah |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment