select.poll.poll() never blocks

Discussion in 'Python' started by birdsong, Feb 12, 2009.

  1. birdsong

    birdsong Guest

    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.
    birdsong, Feb 12, 2009
    #1
    1. Advertising

  2. "birdsong" <>wrote:

    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
    Hendrik van Rooyen, Feb 12, 2009
    #2
    1. Advertising

  3. birdsong

    birdsong Guest

    On Feb 11, 10:36 pm, "Hendrik van Rooyen" <>
    wrote:
    > "birdsong" <>wrote:
    >
    > 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.
    >

    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.
    birdsong, Feb 12, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    3
    Views:
    418
    Scott Allen
    Feb 27, 2005
  2. Soren Kuula
    Replies:
    1
    Views:
    434
    Henry S. Thompson
    Dec 1, 2005
  3. Kevin
    Replies:
    4
    Views:
    403
    Irrwahn Grausewitz
    Oct 17, 2003
  4. Jean-Paul Calderone

    Re: select.poll.poll() never blocks

    Jean-Paul Calderone, Feb 12, 2009, in forum: Python
    Replies:
    3
    Views:
    425
    birdsong
    Feb 12, 2009
  5. matt
    Replies:
    1
    Views:
    233
    George Ogata
    Aug 6, 2004
Loading...

Share This Page