readline() blocks after select() says there's data??
wealthychef
wealthychef at mac.com
Fri Mar 15 13:21:44 EST 2002
"Donn Cave" <donn at drizzle.com> wrote in message news:<1016173476.645562 at yasure>...
> 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 concerns me, because in many cases, it will not be line-oriented.
I need a general tool. I cannot be sure about endlines in general,
although for this case, of course I chose readline() because I am
sure.
If it is not line-oriented, must I then use select.select combined
with read(1) and go character by character?
That reminds me, is there a way to get the integer value of a
character in Python analogous to casting a char to an int in C?
>
> 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.)
This is even more frightening. I don't want to lose any data! How
can I protect myself from this? Why is using the file descriptor
better?
Thanks for the help, good people!
More information about the Python-list
mailing list