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

Kragen Sitaker kragen at pobox.com
Sun Jan 27 01:18:20 EST 2002


"Donn Cave" <donn at u.washington.edu> writes:
> You know,
> - select & poll really use a file "descriptor" - they'll accept various
>   alternatives, but only when there's a callable fileno attribute to
>   return the file descriptor.  And when you go that way, any input
>   through a file object is liable to buffer up data that select can't
>   see, so the file object is little or no use.  Use os.read() instead.

Isn't there a way to fix this?

> - when you use select, that file descriptor does _not_ need to be
>   non-blocking.  select's whole purpose is to tell you when I/O will
>   not block, so if you let it tell you when to read, non-blocking is
>   irrelevant.

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.




More information about the Python-list mailing list