spawning pyhon apps...
bruce
bedouglas at earthlink.net
Fri Jan 9 18:43:25 EST 2009
hi jason....
forgive me... but in your sample:
my_popenobjects = [subprocess.Popen("foo.py", "--filename=file
%i.txt"%x) for x in xrange(10)]
are you spawning 'foo.py' 10 times? that can't be right!
so just what is "foo.py" used for? what am i missing...
it looks like the my_popenobjects array is iterated through to check the
statuscode. is the statuscode the value that would be returned from a child
python script via something like "return(2)"....
i've seen mention of os.waitpid(..) does this play into waiting for child
processes to complete, or determine if they've terminated??
thanks
-----Original Message-----
From: python-list-bounces+bedouglas=earthlink.net at python.org
[mailto:python-list-bounces+bedouglas=earthlink.net at python.org]On Behalf
Of Jason Scheirer
Sent: Friday, January 09, 2009 3:19 PM
To: python-list at python.org
Subject: Re: spawning pyhon apps...
On Jan 9, 2:47 pm, "bruce" <bedoug... at earthlink.net> wrote:
> hi...
>
> 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
> create?
>
> is there another approach? code samples/tutorial...??
>
> i've seen various approaches via google, but not just what i'm looking
for..
>
> thanks
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
my_popenobjects):
time.sleep(0.25)
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.
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list