Python 2.0 - win32pipe routines inclusion for Windows

David Bolen db3l at fitlinxx.com
Thu Jul 27 13:57:17 EDT 2000


Niels Diepeveen <niels at endea.demon.nl> writes:

> David Bolen schreef:
> ...
> > since the os.popen#() routines can standardize on
> > using the first (or only for the original os.popen) file for returning
> > the exit code on the close, and since that's always stdin of the child
> > (except for the pair of os.popen() write modes, for which there's no
> > connection to the child stdin) it minimizes the risk of any deadlock
> > waiting for the child process during the close since the wait is
> > performed as part of closing stdin to the child process.
> 
> I don't quite see how you can safely wait() for the child process before
> you close *all* the pipes. Given that pipes have limited buffer space,
> the child process might want to output more than that amount of data
> after encountering EOF on the input. Consider this example:

Oh I agree - that's the one potential hole that made me say
"minimizes" and not "removes".  It's pretty likely that closing the
child's stdin is going to force some sort of error eventually on the
child if it wasn't closing naturally, but not 100%.

I don't think there's any way for the popen routines themselves to
close this hole however.  The only real fix is to close all files
related to the child process whenever one is closed that needs to
retrieve the exit code.  But that behavior would be fraught with
indirect issues where elsewhere the Python code might not expect
handles other than the one explicitly referenced in the close() to
become closed.

But closing that hole at the application level isn't very difficult.
The application needs to have processed all the child output (through
knowledge of the child), or just explicitly closed the other files
returned by the initial popen# call before doing the final close on
the child-stdin to receive the exit code.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list