Skip to content

Instantly share code, notes, and snippets.

@trhura
Last active December 18, 2015 20:29
Show Gist options
  • Save trhura/5840354 to your computer and use it in GitHub Desktop.
Save trhura/5840354 to your computer and use it in GitHub Desktop.
Python decorator to retry function calls on Exception
import functools
def retry (function, retry=3):
@functools.wraps(function)
def wrapper (*args, **kwargs):
exception = None
for i in range (retry):
try:
return function (*args, **kwargs)
except Exception, ex:
exception = ex
raise exception
return wrapper
@retry
def retry_test ():
raise Exception ('Test Exception')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment