Skip to content

Instantly share code, notes, and snippets.

@coconut49
Last active December 15, 2017 15:22
Show Gist options
  • Save coconut49/5f8b972d04c1c119c68ecf09cc0677fd to your computer and use it in GitHub Desktop.
Save coconut49/5f8b972d04c1c119c68ecf09cc0677fd to your computer and use it in GitHub Desktop.
def ignore_error_and_retry(times=3):
def real_decorator(fn):
def warpper(*args, **kwargs):
try:
fn(*args, **kwargs)
except Exception as e:
print(str(e))
if not hasattr(warpper, "counter"):
warpper.counter = 1
else:
warpper.counter += 1
if warpper.counter <= times:
print("It' function {}'s {} times retry".format(fn.__name__, warpper.counter))
warpper(*args, **kwargs)
return warpper
return real_decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment