Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Created December 16, 2017 16:51
Show Gist options
  • Save charlesreid1/b794c02a8b99a48eb241217322230670 to your computer and use it in GitHub Desktop.
Save charlesreid1/b794c02a8b99a48eb241217322230670 to your computer and use it in GitHub Desktop.
If at first you don't succeed... try, try again!
def retry(func):
maxretries = 10
def wrapper(*args, **kwargs):
for i in range(maxretries, 0, -1):
try:
print('RETRY %d'%(i))
return func(*args, **kwargs)
except (Exception,)[:i - 1]:
pass
return wrapper
@retry
def foo():
raise ValueError
foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment