Select weirdness

Jean-Paul Calderone exarkun at divmod.com
Sun Apr 22 15:37:55 EDT 2007


On Sun, 22 Apr 2007 11:42:10 -0700, Ron Garret <rnospamon at flownet.com> wrote:
>I think I've figured out what's going on.
>
> [snip]
>
>As you can see, the select call shows input available for a while (five
>lines) and then shows no input available despite the fact that there is
>manifestly still input available.
>
>The answer is obvious: select is looking only at the underlying socket,
>and not at the rfile buffers.
>
>So... is this a bug in select?  Or a bug in my code?

In your code, unfortunately.  select() is for file descriptors, not arbitrary
buffering Python file objects.  You shouldn't use readline if you want select
to work right, and vice versa.  Use read() and do your own line buffering
(it's trivial) or don't use select (which I believe has been suggested, and I
can't tell from your code why you want to use select in the first place).

Or avoid the low-level networking entirely and use a high-level HTTP library
that takes care of these details for you.

Jean-Paul



More information about the Python-list mailing list