如何从另一个脚本启动脚本在python
问题描述:
我创建了一个脚本来检查,如果其他一些脚本运行如何从另一个脚本启动脚本在python
import os
import datetime
import time
from time import ctime
statinfo = os.stat('nemo_logs/nemo_log_file_' + time.strftime('%Y-%m-%d') + '.txt')
for i in range(1):
first_size = statinfo.st_size
time.sleep(10)
if statinfo.st_size > first_size:
print("SCRIPT IS RUNNING")
else:
print("SCRIPT IS NOT RUNNING. TRYING TO KILL THE SCRIPT...")
os.system("pkill -9 -f selenium_nemo.py")
print("SCRIPT KILLED. TRYING TO RESTART THE SCRIPT...")
os.system("python selenium_nemo.py")
print("SCRIPT STARTED")
如果脚本日志增加那么我们都OK,但如果剧本一直坚持对于某些情况,我想停止它并重新启动脚本。 首先我杀死脚本,然后我执行os.system("python selenium_nemo.py")
。该脚本启动,但它在我的主脚本中运行。我怎样才能在另一个进程上启动selenium_nemo.py
? “for循环是后来者
感谢
https://docs.python.org/2/library/subprocess.html –
@SimonHibbs我相信这是我在找的东西。非常感谢你 –