select.poll.poll() never blocks

Jean-Paul Calderone exarkun at divmod.com
Wed Feb 11 21:49:09 EST 2009


On Wed, 11 Feb 2009 18:44:53 -0800 (PST), birdsong <david.birdsong at gmail.com> wrote:
>I'm pretty sure I've exhausted all searches and read all the forums
>Google will turn up related to this issue.
>
>I touch an empty file in a sh shell, fire up the python shell, open
>the file for reading(tried all buffering options), register it with a
>poll object for select.POLLIN and call poll(), but the poll never
>blocks and always returns for the FD, EVENT combination I ask for, but
>the file has not anything written to it.

Filesystem files are always reported as readable and writeable by select,
poll, epoll, etc.

If you want to do non-blocking filesystem I/O, your choices are to use a
native thread (Python's threading module, or another third-party module
which wraps the platform thread API) or to use POSIX AIO (or the mildly
incompatible Linux variant.  Of course, AIO has tons of caveats and is
generally in a miserable state, so you probably shouldn't use it.  That
leaves you with threads.

Jean-Paul



More information about the Python-list mailing list