Last active
June 18, 2021 10:01
-
-
Save umangshrestha/b3ad9a3bc0d659598049888decea9777 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 retry(retry_count=2, time_out=1): | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
init_time = time() | |
for i in range(1, retry_count): | |
print("loop count: %d" % i) | |
while (time() - init_time <= time_out): | |
# if the execution happends we return output | |
# Incase it failes we will retrun the funciton for timeout seconds | |
# If it executes without error in any of the retruns we return the output | |
# Still if issue is seen we will allow it to redo the process for retry_count | |
# even after all that function fails we will return false | |
try: | |
print("executing---> %s()"% f.__name__) | |
out = func(*args, **kwargs) | |
return out; | |
except Exception as e: | |
print("error---->",e.__class__) | |
return False | |
return wrapper | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment