[Python-Dev] socket timeouts fail w/ makefile()
Skip Montanaro
skip@pobox.com
Thu, 20 Mar 2003 21:15:45 -0600
>> 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.
>> 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.
Guido> There's code for Windows that emulates it, returning a file-like
Guido> object. Maybe that code should be enabled universally rather
Guido> 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.
Skip