import random↵
import time↵
↵
↵
def retry(attempts=5, base=0.5):↵
def wrap(fn):↵
def run(*args, **kwargs):↵
for i in range(attempts):↵
try:↵
return fn(*args, **kwargs)↵
except ConnectionError:↵
if i == attempts - 1:↵
raise↵
time.sleep(base * 2 ** i + random.random() / 10)↵
return run↵
return wrap
Click here or press any key to type