Skip to content

Instantly share code, notes, and snippets.

@j-griffith
Created October 9, 2014 16:48
Show Gist options
  • Save j-griffith/1c1c668dde70c1e1b011 to your computer and use it in GitHub Desktop.
Save j-griffith/1c1c668dde70c1e1b011 to your computer and use it in GitHub Desktop.
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