popen with separete stdout/stderr deadlock.

David Bolen db3l at fitlinxx.com
Fri Nov 30 18:26:58 EST 2001


Kragen Sitaker <kragen at pobox.com> writes:

> Eyal Lotem <eyal at hyperroll.com> writes:
> > When running popen with a separate stdout/stderr, can I use read() on the 
> > resulting stdout file? it seems to 'hang', and I'm assuming stderr's buffer 
> > is stuck on write (as it is all filled up), and my stdout read() is stuck 
> > on waiting for EOF, which will never come.  Deadlock.
> > 
> > Is this really what's happening and how can it be avoided?
> 
> Could be.  import select and use select.select to avoid it.

Or if you're under Windows (where you can't select on a file handle),
one classic solution is to multi-thread so you can drain (or feed) all
the handles simultaneously.  You can still create a deadlock if you
incorrectly synchronize your threads and re-create dependencies but in
general it's fairly easy to work around.

--
-- 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