Skip to content

Instantly share code, notes, and snippets.

@elowy01
Created November 26, 2019 16:28
Show Gist options
  • Save elowy01/a8541d6853d572346e073e7fc1dd3a2b to your computer and use it in GitHub Desktop.
Save elowy01/a8541d6853d572346e073e7fc1dd3a2b to your computer and use it in GitHub Desktop.
import requests
import time
def retry(cooloff=5, exc_type=None):
if not exc_type:
exc_type = [requests.exceptions.ConnectionError]
def real_decorator(function):
def wrapper(*args, **kwargs):
while True:
try:
return function(*args, **kwargs)
except Exception as e:
if e.__class__ in exc_type:
print "failed (?)"
time.sleep(cooloff)
else:
raise e
return wrapper
return real_decorator
@retry(exc_type=[ZeroDivisionError])
def test():
return 1/0
print test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment