I'm currently running a python code "Restart.py" in order to restart another python script "Tracking.py" using Shell 'restart.sh'.
The shell script launches "Tracking.py" and creates a .log file which stores all the print from "Tracking.py" which is mainly a kind of monitoring text.
Sometimes it happens that "Traking.py" crashes with a message of : "During handling of the above exception, another exception occured" which is written in the .log file.
Then, "restart.py" script reads the .log file every 20sec and when he finds a key word : "exception" it is supposed to delete .log file and then executes restart.sh (which will recreate a new .log file)
Here the code
import subprocess import os import time while True: with open("log.log",'r') as f: for line in f: if "exception" in line: os.remove('log.log') wait = 20 time.sleep(wait) subprocess.call(["sh", "./restart.sh"]) When it comes the crash, the script restarts well the shell script (and Tracking.py) but it doesn't delete log.log file and so keep storing all the print in the undeleted .log file.
Could you please tell me what is wrong?
"exception"appears in any line.