nonblocking read()

Peter Ammon peter_ammon at rocketmail.com
Mon Nov 15 19:08:00 EST 2004


I would like to read from a pipe in which data may arrive slowly.  From 
experimenting, it looks like os.read() will block until it returns the 
maximum amount of data you asked for, in the second parameter to read(), 
or until it hits EOF.  I cannot find a way to return only the data that 
the file object has immediately available.

If no data is available, blocking is OK.

The only workaround I can think of is to call select() in a loop, 
reading and storing one byte each time, and then returning them when 
select() indicates that the pipe is not ready for reading.

Are there better approaches?  Thanks,

-Peter



More information about the Python-list mailing list