So I've got something of the form:
def func():
while True:
do_stuff()
try:
func()
except:
func()
I had expected that if anything happened to my func loop, it would start again, however in actual fact errors cause it to crash. How can I make it just restart if anything goes wrong?
You can try placing the try-except inside a while loop and use pass in the except block.
Ex:
def func():
while True:
do_stuff()
while True:
try:
func()
except:
pass
What are you trying to achieve? Keeping a program run is generally not the responsibility of the program itself. If you are on a UNIX-like operating system, you can use Supervisord to automatically run processes and let them restart if they fail. If you are on Windows, this answer may help you out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With