Skip to content

Instantly share code, notes, and snippets.

@ssbb
Created March 6, 2015 19:53
Show Gist options
  • Save ssbb/6d93792295f5acd95479 to your computer and use it in GitHub Desktop.
Save ssbb/6d93792295f5acd95479 to your computer and use it in GitHub Desktop.
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