spawning pyhon apps...

Chris Rebert clp2 at rebertia.com
Fri Jan 9 18:53:21 EST 2009


On Fri, Jan 9, 2009 at 3:43 PM, bruce <bedouglas at earthlink.net> wrote:
> 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!

Indeed, it probably ought to be (note the 2nd pair of brackets):
my_popenobjects = [subprocess.Popen(["foo.py",
"--filename=file%i.txt"%x]) for x in xrange(10)]

> so just what is "foo.py" used for? what am i missing...

It's the name of the program you want to run. In this case, it happens
to be a Python script.

>
> 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)"....

It's the POSIX exit code of the program (i.e. what int you return from
main() in a C program, or what you pass to sys.exit() in Python)

> i've seen mention of os.waitpid(..) does this play into waiting for child
> processes to complete, or determine if they've terminated??

Don't know specifically, but that's another, lower-level API. The
`subprocess` module is superior.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list