简体   繁体   中英

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.

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.

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. I need a way to execute script2 and let it run and terminate script1

script_1.py:

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

script_2.py:

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

在此处输入图片说明

After adding in process.wait() to script_1.py:

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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