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

Donn Cave donn at drizzle.com
Fri Mar 15 01:24:38 EST 2002


Quoth grante at visi.com (Grant Edwards):
...
| When select returns a file descriptor, that means that read()
| won't block.  If only a partial line is available, then
| readline() will still block.  I doubt that this is going to be
| an issue, since your output is probably line-oriented.

That's a good point.

The complementary problem, of course, is that once you have invoked
readline(), it will read all the data available on the file descriptor,
or a lot of it anyway, and return only the first line.  The next time,
it will return the next line from its buffer, but you have no way to
know that it has another line waiting there.  select() can't see it.
There are solutions, I think the easiest thing in most cases is to
throw away the file object and just use the file descriptor (fileno())
(or sockets in this case.)

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list