readline() blocks after select() says there's data??

Rich Cook wealthychef at mac.com
Fri Mar 15 12:07:46 EST 2002


At 10:57 AM -0600 3/15/02, Skip Montanaro wrote:
>     Rich> I don't really need select to block.  I just want it to be
>     Rich> accurate.  If it returns a file object in the list of things which
>     Rich> are available, why should then readline() block on it?
>
>Remember that select() is lower level than readline().  As someone else
>pointed out, select() may return because there is data available, but it
>makes no promises about what that data is.  Calling readline() may then hang
>waiting for other conditions (presence of a newline in the input, for
>example).

So do I have to read the data byte by byte using read(1) and examine 
each character to avoid blocking?  Is there any way to find out how 
much data is actually waiting for me in the file object so I can read 
it in bigger increments, or must I call select then read(1) for every 
byte?
The reason I'm concerned is that I have two file objects (childerr 
and fromchild, actually) and I want to know right away if one has 
data.  So I can't just call read on either one, because I may get 
blocked on one waiting for data from the other.  But I'd like to 
avoid the char-by-char read if possible.
-- 

-Sincerely, Rich Cook 925-784-3077
*******************************************************************
Sometimes it is said that man cannot be trusted with the government 
of himself. Can he, then, be trusted with the government of others?
         Thomas Jefferson
*******************************************************************




More information about the Python-list mailing list