简体   繁体   English

Subprocess.Popen 没有运行另一个脚本

[英]Subprocess.Popen not running another script

I have script1.py which does some calculations and sends some emails and script2.py (is used to do some updated in a Mysql DB) which is in an infinite loop until some things are satisfied.我有 script1.py 进行一些计算并发送一些电子邮件和 script2.py(用于在 Mysql DB 中进行一些更新),它处于无限循环中,直到某些事情得到满足为止。

At the end of the calculations made on script1, I need to execute script2.py and to do this I am using subprocess.Popen(["python", "script2.py"]) now when debugging this, I see that it goes inside script2 and it works but when the execution of script1 ends I see that the script2.py stops its execution.在对 script1 进行的计算结束时,我需要执行 script2.py 并为此我在调试时使用subprocess.Popen(["python", "script2.py"])现在,我看到它在 script2 中,它可以工作,但是当 script1 的执行结束时,我看到 script2.py 停止执行。

Is there another module used to do this kind of things, because it's not working properly ?是否有另一个模块用于执行此类操作,因为它无法正常工作?

EDIT: I need to execute script1.py in order to execute script2.py but when using subprocess.Popen() the script1 waits for the script2 to terminate the execution.编辑:我需要执行 script1.py 才能执行 script2.py 但在使用 subprocess.Popen() 时,script1 等待 script2 终止执行。 I need a way to execute script2 and let it run and terminate script1我需要一种方法来执行 script2 并让它运行并终止 script1

script_1.py:脚本_1.py:

import subprocess
process = subprocess.Popen(["python", "script_2.py"])
print("CONTROLLER TERMINATED")

script_2.py:脚本_2.py:

import time
for x in range(5):
    print("ALIVE")
    time.sleep(1)

在此处输入图片说明

After adding in process.wait() to script_1.py:process.wait()添加到 script_1.py 后:

import subprocess
process = subprocess.Popen(["python", "script_2.py"])
process.wait()
print("CONTROLLER TERMINATED")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM