Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force 2 Python subprocesses to run one after the other

I want to run 2 programs in Python one after the other. I use Popen but it appears they run in parallel. I have something like this:

p1 = Popen(['./program1'])
p2 = Popen(['./program2'])

How can I make p2 to start only when p1 finish?

Thank you

like image 790
cody Avatar asked Dec 13 '25 03:12

cody


1 Answers

this should work.

p1 = Popen(['./program1'])
p1.wait()
p2 = Popen(['./program2'])
p2.wait()

it will cause the program to block until each subprocess exits.

like image 109
ragingSloth Avatar answered Dec 15 '25 22:12

ragingSloth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!