Created
March 6, 2015 19:53
-
-
Save ssbb/6d93792295f5acd95479 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(times, *exception_types): | |
def try_it(func, *fargs, **fkwargs): | |
for i in xrange(times - 1): | |
try: | |
return func(*fargs, **fkwargs) | |
except exception_types or Exception: | |
pass | |
return func(*fargs, **fkwargs) | |
return try_it | |
@retry(3) | |
def do_something(): | |
raise ValueError('Something was broken.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment