Created
December 16, 2017 16:51
-
-
Save charlesreid1/b794c02a8b99a48eb241217322230670 to your computer and use it in GitHub Desktop.
If at first you don't succeed... try, try again!
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(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