I have a program that starts four others and I want them to run simultaneously which I can do with subprocess.Popen()
and I want to check if they started correctly. If not, do nothing and wait until the next time it gets called. I'm working on windows and this is what I have so far but I'm not positive this works the way I think it will and I don't know how to test it other than sit around and hope it fails but continues on. Can someone tell me if this will work or not and if not why?
import subprocess
import time
from datetime import datetime
while 1:
Day = time.strftime('%d')
Month = time.strftime('%m')
Year = time.strftime('%Y') #if conditions are just right(the day changes before month and year are calculated) then the dates could get off (highly unlikely)
start = time.clock()
try:
p1 = subprocess.Popen(['python', 'C:/Users/tnabrelsfo/Documents/Programs/strippers/TransmitterStrip.py'], stdout=None)
except OSError:
print('Error with Transmitter')
try:
p2 = subprocess.Popen(['python', 'C:/Users/tnabrelsfo/Documents/Programs/strippers/ReceiverStrip.py'], stdout=None)
except OSError:
print('Error with Receiver')
try:
p3 = subprocess.Popen(['python', 'C:/Users/tnabrelsfo/Documents/Programs/strippers/UIDStrip.py'], stdout=None)
except OSError:
print('Error with UID')
try:
p4 = subprocess.Popen(['python', 'C:/Users/tnabrelsfo/Documents/Programs/strippers/BlueStripper.py'], stdout=None)
except OSError:
print('Error with Blue')
p1.wait()
p2.wait()
p3.wait()
p4.wait()
print('Duration: %.2f' % (time.clock()-start))
print('\n' + str(datetime.now()) + '\n')
print('Done with run')
for x in range(301):
time.sleep(1)