subprocess can't successfully restart the targeted python file
问题 I write a program my_test.py to get data from web and store to mysql. But the program my_test.py collapses a lot (my bad programming skill...) and I try to monitor its status and restart it when it collapses. I use subprocess modular with the following codes. import subprocess import time p = subprocess.Popen(['python.exe', r'D:\my_test.py'], shell=True) while True: try: stopped = p.poll() except: stopped = True if stopped: p = subprocess.Popen(['python.exe', r'D:\my_test.py'], shell=True)