Created
January 29, 2020 10:20
-
-
Save fadziljusri/7ecedb91d8b260449bbc6fae031cba60 to your computer and use it in GitHub Desktop.
Python handle unexpected error and re-run app for retry counter
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
from time import sleep | |
do_error = None | |
def run(retry=0): | |
try: | |
print(do_error[1]) | |
except Exception as e: | |
err_type = e.__class__.__name__ | |
if err_type: | |
retry += 1 | |
if retry <= 2: | |
print("{}:".format(err_type), "retry in 3s") | |
sleep(2) | |
run(retry=retry) | |
return | |
print("{}, im done with u".format(err_type)) | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment