Answer the question
In order to leave comments, you need to log in
How to restart a file after an error?
try/except (and finally) won't work because the error occurs in the except block. It is necessary that the file (or code) is completely restarted after an error. I heard something about systemd and restart: on-failure in it, but did not understand how to use this thing.
Answer the question
In order to leave comments, you need to log in
Based on systemd, are you on Linux? So you have os.system (command) will return the exit code, which is equal to zero on normal completion.
import os
while True:
exit_code = os.system("python3 script.py") # Возможно тут следует написать полные пути
if exit_code == 0:
print("success!")
break
print(f"exit_code is {exit_code}, will retry")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question