Last active
December 15, 2017 15:22
-
-
Save coconut49/5f8b972d04c1c119c68ecf09cc0677fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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