Created
November 26, 2019 16:28
-
-
Save elowy01/a8541d6853d572346e073e7fc1dd3a2b 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
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