import functools
def retry(on: list, limit: int):
def decorator_retry(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
i = 0
while i < limit:
try:
return func(*args, **kwargs)
break
except Exception as e:
if avoid and not any(x in str(e) for x in avoid):
print('Retrying:', e)
else:
raise e
i += 1
return wrapper
return decorator_retry
# example
@retry(on=['TimeoutError'], limit=3)
def crawl(url):
pass