managing multiple subprocesses

Marcos seejadee at gmail.com
Wed Feb 2 19:10:16 EST 2005


Hi guys,
I realise this question has been answered in one form or another many
times before but I can't quite find the solution I need. I am trying to
run multiple subprocesses from a python script and then wait until all
subprocesses have completed before continuing. The subprocesses run on
other machines ie this is a coarse grained parallel computation task.

So the commands I am using are:
for x in range(0, limit):
os.system("xgrid .... ./someprogram %d &" % x)

and then to check whether they are all finished I do a very crude:

joblist = commands.getoutput("xgrid .... -job list")
while joblist != "{jobArray = (); }":
time.sleep(1)
joblist = commands.getoutput("xgrid .... -job list")

Xgrid is a system for parallel computation on Mac OS X. It is quite
good, check it out at www.apple.com/acg/xgrid. But anyway the method I
am using above, while it works, it quite often hangs. I'd like to just
run all the subprocesses at once and then check within the script,
rather than an auxilliary, to see if everything has returned. The
output of the commands is not important as that gets redirected to
files outside the script. I have tried all sorts of popens / excevs /
os.systems / commands etc etc. I realise the subprocess module may have
what I need but I can't get python 2.4 on the Mac so I need a 2.3 based
solution. Any help is much appreciated. Cheers.




More information about the Python-list mailing list