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)
time.sleep(60)
But when my_test.py
collapses, a windows warning window jumps out to alert me that my_test.py
is down and which action I will choose: stop, debug ...
Something like that.
And my_test.py
seems frozen by the alert windows and the codes above can't restart it successfully.
Only when I manually close the window by choose 'close', it will restart again.
It there any solution to this problem such that my codes can successfully restart my_test.py
when it breaks down?
Sorry for the inconvinience brought by my poor English and thank in advance for your kind advices.