[Python-Dev] socket timeouts fail w/ makefile()
Guido van Rossum
guido@python.org
Fri, 21 Mar 2003 06:17:29 -0500
> >> I discovered much to my chagrin today that the socket
> >> module's new timeout capability doesn't play well with file
> >> objects as returned by a socket's makefile method.
>
> Guido> Can you explain better how it doesn't work?
>
> When the socket is in non-blocking mode, reads on the file returned by
> .makefile() will fail with an IOError if there is nothing to return.
Isn't that exactly what a timeout is supposed to do? What would you
have expected?
> >> I would think the greatest use of timeouts would be using
> >> higher-level line-oriented modules like urllib and ftplib. In
> >> addition, since makefile() isn't always available, it seems
> >> worthwhile to implement something in socket.py, thus making
> >> makefile() universally available.
>
> Guido> Um, when is makefile() not available?
>
> I don't know. I was going by the doc string in socketmodule.c which
> says, in part:
>
> ...
> makefile([mode, [bufsize]]) -- return a file object for the socket [*]\n\
> ...
> [*] not available on all platforms!");
>
> Maybe the docs are just wrong. According to the #ifdef in the code, if
> NO_DUP is defined (OS/2, Windows, BeOS), makefile() isn't.
That's the docs for the _socket module, which is (nowadays) an
implementation detail. Read socket.py instead.
> Guido> There's code for Windows that emulates it, returning a
> Guido> file-like object. Maybe that code should be enabled
> Guido> universally rather than only on Windows...
>
> That sounds similar to what is in timeoutsocket.py. It would have the
> advantage of providing identical semantics across all platforms.
Again, I won't have time to do this until after I'm back from Python
UK, so I'd appreciate it if someone helped with this, e.g. by filing a
patch.
--Guido van Rossum (home page: http://www.python.org/~guido/)