python – wait process until all subprocess finish?
Popen object has a
.wait() method exactly defined for this: to wait for the completion of a given subprocess (and, besides, for retuning its exit status).
If you use this method, youll prevent that the process zombies are lying around for too long.
(Alternatively, you can use
subprocess.check_call() for calling and waiting. If you dont need IO with the process, that might be enough. But probably this is not an option, because your if the two subprocesses seem to be supposed to run in parallel, which they wont with (
If you have several subprocesses to wait for, you can do
exit_codes = [p.wait() for p in p1, p2]
which returns as soon as all subprocesses have finished. You then have a list of return codes which you maybe can evaluate.
Automatically waits , you can also use: