简体   繁体   English

从脚本启动不同的脚本

[英]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? 即如何从一个脚本同时启动两个脚本?

  1. If I just try to run the script using "import script2" I get an error 如果我只是尝试使用“导入脚本2”运行脚本,则会收到错误消息

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.

相关问题 使用输入将用户从菜单脚本定向到其他脚本? - Directing a user to different scripts from a menu script using inputs? 如何使用其他脚本启动和停止脚本? - How to start and stop scripts using another script? 如何在单独的窗口中从python脚本启动子cmd终端并在其上执行脚本? - How to start child cmd terminals in separate windows, from python script and execute scripts on them? 无法通过“python script.py”从脚本文件夹启动文件 - can not start files from scripts-folder via "python script.py" 如何从一个父脚本的不同文件夹运行多个脚本 - How to run multiple scripts from different folders from one parent script 将用 2 个不同文字写成的句子音译成一个文字 - Transliterate sentence written in 2 different scripts to a single script 如何使用python脚本启动其他python脚本并检查所有“子脚本”是否都已完成? - How to use python script to start other python scripts and check whether all “child scripts” are finished? 从主 sh 脚本调用 5 个 sh 脚本 - Call 5 sh scripts from main sh script 如何从python中的脚本运行多个脚本 - How to run multiple scripts from a script in python Python 运行与我的脚本不同的脚本 - Python run separate scripts from my script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM