Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
import functools, time def retry(times=3, delay=1): def decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): for attempt in range(times): try: return func(*args, **kwargs) except Exception as e: if attempt == times - 1: raise time.sleep(delay) return wrapper return decorator @retry(times=3, delay=0.5) def fetch_data(): pass # network call here
Result
Open