Skip to content

Instantly share code, notes, and snippets.

@eduzen
Created November 30, 2021 14:15
Show Gist options
  • Save eduzen/a1a39b244056d7bfbea2a10f030bcea6 to your computer and use it in GitHub Desktop.
Save eduzen/a1a39b244056d7bfbea2a10f030bcea6 to your computer and use it in GitHub Desktop.
from functools import wraps
import time
def try_until_you_find_it(retries=1, wait_time=1):
def decorator(func):
@wraps(func)
def wrapped_func(*args, **kwargs):
for n in range(retries):
try:
return func(*args, **kwargs)
except Exception as e:
print(str(e))
time.sleep(wait_time)
return wrapped_func
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment