strangethingspy
strangethingspy

Reputation: 246

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

Upvotes: 1

Views: 417

Answers (1)

Zak Stucke
Zak Stucke

Reputation: 452

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)

enter image description here

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

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

enter image description here

Upvotes: 1

Related Questions