[英]Start different scripts from script
我想在PythonAnywhere上運行幾個腳本。 為了確保腳本不會被殺死,我想每隔五分鍾檢查一次腳本的狀態(基於https://help.pythonanywhere.com/pages/LongRunningTasks/ )。
出現兩個問題:1.在每五分鍾運行一次的腳本中,我想檢查其他腳本(script2,script3)是否仍然存在。 如果沒有,我顯然想運行它們。 但是,如何從一個腳本(script1)運行多個腳本而又不會使script1陷入困境? 即如何從一個腳本同時啟動兩個腳本?
ImportError:沒有名為script2的模塊
如何告訴Python該腳本位於其他文件夾中(因為這是問題所在)?
提前致謝!
嘗試這個:
import time
import subprocess
def check_process(proc,path):
if proc.poll()!=1:
print('%s still running' % proc)
elif proc.poll()==1:#will give a 1 if the child process has been killed
print('%s is dead. Re-running')
subprocess.Popen(['python.exe', path])
script1=subprocess.Popen(['python.exe', pathscript1])
script2=subprocess.Popen(['python.exe', pathscript2])
while True:
check_process(script1,pathscript1)
check_process(script2,pathscript2)
time.sleep(300)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.