Popen

Diez B. Roggisch deets at nospam.web.de
Fri Jul 24 12:35:56 EDT 2009


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.

Diez



More information about the Python-list mailing list