[英]Start different scripts from script
I would like to have several scripts running on PythonAnywhere. 我想在PythonAnywhere上运行几个脚本。 In order to make sure that the scripts are not killed I would like to check for their status in an interval of five minutes (based on https://help.pythonanywhere.com/pages/LongRunningTasks/ ).
为了确保脚本不会被杀死,我想每隔五分钟检查一次脚本的状态(基于https://help.pythonanywhere.com/pages/LongRunningTasks/ )。
Two questions arise: 1. In the script which runs every five minutes I would like to check whether the other scripts (script2, script3) are still alive or not. 出现两个问题:1.在每五分钟运行一次的脚本中,我想检查其他脚本(script2,script3)是否仍然存在。 If not, I would obviously like to run them.
如果没有,我显然想运行它们。 But how do I run several scripts from one script (script1) without script1 getting "stuck"?
但是,如何从一个脚本(script1)运行多个脚本而又不会使script1陷入困境? Ie how do I start two scripts at the same time from one script?
即如何从一个脚本同时启动两个脚本?
ImportError: No module named script2
ImportError:没有名为script2的模块
How do I tell Python that the script is in a different folder (because that has to be the issue)? 如何告诉Python该脚本位于其他文件夹中(因为这是问题所在)?
Thanks in advance! 提前致谢!
Try this: 尝试这个:
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.