On Jul 24, 6:24 pm, Tim <timlee...@yahoo.com> wrote: > 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.
This is correct > 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. > Calling result.readlines() the parent process attempts to read from stdout until end of file. For a pipe, end of file means that the other end is closing its connection, which - unless the child process closes stdout explicitely - means that the child process is terminated. So the end effect is the almost like using 'communicate' on the result of Popen, except that communicates returns both standard output and standard error contents at the same time. > So how to understand the meaning of "asynchronous"? > > Thanks and regards! HTH Ciao ----- FB -- http://mail.python.org/mailman/listinfo/python-list