2017-04-21 132 views
1

我創建了一個腳本來檢查,如果其他一些腳本運行如何從另一個腳本啓動腳本在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循環是後來者

感謝

+3

https://docs.python.org/2/library/subprocess.html –

+1

@SimonHibbs我相信這是我在找的東西。非常感謝你 –

回答

2

可以使用subprocess模塊這一點。 查看此answer瞭解更多。

相關問題