non blocking read()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Uwe Mayer

    #1

    non blocking read()

    Hi,

    I use select() to wait for a file object (stdin) to become readable. In that
    situation I wanted to read everything available from stdin and return to
    the select statement to wait for more.

    However, the file object's read method blocks if the number of bytes is 0 or
    negative.

    Is there no way to read everything a channel's got currently got without
    blocking?

    Uwe
  • Donn Cave

    #2
    Re: non blocking read()

    In article <col35h$cmf$1@n ews2.rz.uni-karlsruhe.de>,
    Uwe Mayer <merkosh@hadiko .de> wrote:
    [color=blue]
    > Hi,
    >
    > I use select() to wait for a file object (stdin) to become readable. In that
    > situation I wanted to read everything available from stdin and return to
    > the select statement to wait for more.
    >
    > However, the file object's read method blocks if the number of bytes is 0 or
    > negative.
    >
    > Is there no way to read everything a channel's got currently got without
    > blocking?[/color]


    Yes, there is a way - os.read() (also known as posix.read())

    It's better not to mix buffered I/O (like file object
    I/O functions) with select() at all, because select()
    actually applies to system level file descriptors and
    doesn't know anything about the buffer.

    Get the file descriptor with fileno(), and never refer
    to the file object again after that.

    Donn Cave, donn@u.washingt on.edu

    Comment

    Working...