Python Retry Decorator
PythonRetry a flaky call a fixed number of times.
Remixed from Exponential Backoff with Jitter by Zainab Bello
Python · 11 lines
copied 39 times
def retry(times=3):
def decorator(func):
def wrapper(*args, **kwargs):
for attempt in range(times):
try:
return func(*args, **kwargs)
except Exception:
if attempt == times - 1:
raise
return wrapper
return decorator
5
Fire
2
Learned something
2
Saved me time
5
Mind-blown
Sign in to react and star