select.poll.poll() never blocks

birdsong david.birdsong at gmail.com
Wed Feb 11 21:44:53 EST 2009


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.

Here's an example snippet:
>>> fd = os.open('/tmp/poll_test', os.O_RDONLY | os.O_SYNC)
>>> p = select.poll()
>>> p.register(fd, select.POLLIN)
>>> s = p.poll()
>>> os.read(fd, 10)
''
>>> s
[(3, 1)]
>>> fd
3

I was using the open builtin originally, but a forum I read suggested
that this created user level buffers that the system call wouldn't
know about(which didn't completely jive with me), so I switched to the
lower level os.open.

Am I not getting the proper spirit of select.poll?  I know that read()
never blocks and I think I read somewhere that poll will return fd
that will not block for the EVENT registered -so in that regard it's
fitting.

Any help on what I'm missing would be appreciated.



More information about the Python-list mailing list