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 30 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
2
Fire
0
Learned something
0
Saved me time
4
Mind-blown
Sign in to react and star