Chris Rebert clp2 at rebertia.com
Fri Jul 24 19:28:10 CEST 2009

> --- On Fri, 7/24/09, Diez B. Roggisch <deets at nospam.web.de> wrote:
>> From: Diez B. Roggisch <deets at nospam.web.de>
>> Subject: Re: Popen
>> To: python-list at python.org
>> Date: Friday, July 24, 2009, 12:35 PM
>> Tim schrieb:
>> > Thanks! Yes I mean subprocess.Popen.
>> >
>> > I was wondering the meaning of "asynchronously"
>> > Here is some code I am reading recently:
>> > "
>> > result = Popen(cmdline,shell=True,stdout=PIPE).stdout
>> for line in result.readlines():
>> >     if find(line,"Cross") != -1:
>> >         return
>> float(split(line)[-1][0:-1]) "
>> > The computation in the program "cmdline" takes a long
>> time, at the end of which the results will be output to
>> stdout.
>> >
>> > "asynchronous" seems to mean Popen returns to the
>> parent process immediately and the parent and child
>> processes continue to be executed.
>> > However, if Popen returns immediately to the parent
>> process, then there will be nothing in "result", not to
>> mention extracting information from the output. Thus it
>> seems to me the parent process has to wait till the child
>> process finish.
>> >
>> > So how to understand the meaning of "asynchronous"?
>> "Asynchronous" means asynchronous - the parent is *not*
>> waiting.
>> Which is the reason that there is (amongst other things)
>> the "wait"-method you can call to wait for the child to be
>> terminated.

On Fri, Jul 24, 2009 at 9:52 AM, Tim<timlee126 at yahoo.com> wrote:
> Thanks! If that is the case, i.e. the parent doesn't wait, is the code in my last post wrong? "result" could be nothing.

No, it will be a subprocess.Popen object representing the spawned
process. Both the child process and the parent Python process will
then be running simultaneously.This allows the Python program to
interact with the subprocess via the Popen object while the subprocess
is executing in parallel with Python.
The asynchronicity means that the call to the Popen constructor does
not wait for the spawned subprocess to terminate before returning the
new Popen object to the parent Python program.


More information about the Python-list mailing list