I'm running some subprocesses from python in parallel. I want to wait until every subprocess have finished. I'm doing a non elegant solution:
runcodes = ["script1.C", "script2.C"]
ps = []
for script in runcodes:
args = ["root", "-l", "-q", script]
p = subprocess.Popen(args)
ps.append(p)
while True:
ps_status = [p.poll() for p in ps]
if all([x is not None for x in ps_status]):
break
is there a class that can handle multiple subprocess? The problem is that the wait
method block my program.
update: I want to show the progress during the computation: something like "4/7 subprocess finished..."
If you are curious root
compile the c++ script and execute it.
If your platform is not Windows, you could probably select against the stdout pipes of your subprocesses. Your app will then block until either:
Non-fleshed-out example using epoll with Linux 2.6.xx:
How about
You could do something like this:
The processes will run in parallel, and you'll wait for all of them at the end.