Skip to content

Instantly share code, notes, and snippets.

@fadziljusri
Created January 29, 2020 10:20
Show Gist options
  • Save fadziljusri/7ecedb91d8b260449bbc6fae031cba60 to your computer and use it in GitHub Desktop.
Save fadziljusri/7ecedb91d8b260449bbc6fae031cba60 to your computer and use it in GitHub Desktop.
Python handle unexpected error and re-run app for retry counter
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