select.poll.poll() never blocks

B

birdsong

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

Hendrik van Rooyen

8<----------- select not blocking on empty file stuff -----------------
Any help on what I'm missing would be appreciated.

Why do you expect it to block?
It is ready to read, to return end of file.

- Hendrik
 
B

birdsong

8<----------- select not blocking on empty file stuff -----------------


Why do you expect it to block?
It is ready to read, to return end of file.
I expected it to block because of the name and meaning of the flag,
POLLIN, which I thought meant new data has arrived to be read. Since
I only registered a single file descriptor, I would have expected poll
to not return until there was new data to be read. I understand now
that it is not the case.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top