spawning pyhon apps...
jason.scheirer at gmail.com
Sat Jan 10 00:19:26 CET 2009
On Jan 9, 2:47 pm, "bruce" <bedoug... at earthlink.net> wrote:
> toying with an idea.. trying to figure out a good/best way to spawn multiple
> python scripts from a parent python app. i'm trying to figure out how to
> determine when all child apps have completed, or to possibly determine if
> any of the child processes have died/halted..
> parent app
> spawn child1
> spawn child2
> spawn child3
> spawn childn
> do i iterate through a os.waitpid(pid) for each pid of the child processes i
> is there another approach? code samples/tutorial...??
> i've seen various approaches via google, but not just what i'm looking for..
Investigate the subprocess module, you probably want Popen objects.
You can do a poll loop like
my_popenobjects = [subprocess.Popen("foo.py", "--filename=file
%i.txt"%x) for x in xrange(10)]
while any(popenobject.statuscode is None for popenobject in
If your tasks are more like function calls and less like shell
scripts, then investigate writing your python as an importable module
and use the multiprocessing module, which will do threading/
subprocessing for you.
More information about the Python-list