how to get non-blocking file descriptors from a popen?

Kragen Sitaker kragen at pobox.com
Mon Jan 28 22:25:32 CET 2002


"Donn Cave" <donn at u.washington.edu> writes:

> Quoth Kragen Sitaker <kragen at pobox.com>:
> | I always set non-blocking mode anyway, because I've run into problems
> | when I don't in the past.  I seem to recall that either read or write
> | or both will try to read or write more than is possible and will end
> | up blocking unless you mark the fd nonblocking.  Also, on some
> | operating systems, some file descriptors can become readable
> | temporarily and then become unreadable again (i.e. reads will block).
> | So, all in all, it's best to treat select()'s results as a hint, and
> | use non-blocking I/O as a backup.
> 
> Could be.  I don't write for the operating system I think you're
> talking about.  If select reports that there's data to read, and
> read() blocks, you have a broken select, so it's hard to say what
> it's good for.

Linux does this sometimes on listening sockets.  (So, of course, it's
accept() that blocks, not read().)

Even if your select() is broken in this way, it can still be very
useful if it never fails to tell you a socket is readable when it
really is.  :)




More information about the Python-list mailing list