Python sys.stdin.read(max) blocks until max is read (if max>=0), blocks until EOF else, but select indicates there is data to be read

后端 未结 1 896
盖世英雄少女心
盖世英雄少女心 2021-02-20 11:38

My problem is:

select indicates that there is data to be read, I want to read whatever is there, I do not want to wait for a max amount to be p

相关标签:
1条回答
  • 2021-02-20 11:50

    In os module there is os.read function that allows lower level control over reading from file descriptor. It is nonblocking as long as there is at least a byte ready to read.

    os.read(fd, n)
    

    Read at most n bytes from file descriptor fd. Return a string containing the bytes read. If the end of the file referred to by fd has been reached, an empty string is returned.

    Availability: Unix, Windows.

    Note: This function is intended for low-level I/O and must be applied to a file descriptor as returned by os.open() or pipe(). To read a “file object” returned by the built-in function open() or by popen() or fdopen(), or sys.stdin, use its read() or readline() methods.

    0 讨论(0)
提交回复
热议问题