我有一个程序启动另外四个,我希望它们可以同时运行,我可以用subprocess.Popen()
执行,我想检查它们是否正确启动。如果没有,请不要做任何事情,等到下次调用它。我正在研究Windows,这是我到目前为止所做的,但我不是肯定的,这是按照我认为的方式工作,我不知道如何测试它,除了坐下来,希望它失败但继续。有人可以告诉我这是否有效,如果不是为什么?
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)