Socket timeouts for HTTP connections (httplib)?

Skip Montanaro skip at pobox.com
Wed Apr 2 13:00:32 EST 2003


    Rene> It's in 2.3:
    Rene> http://www.python.org/2.3/highlights.html

    Rene> But I don't know if and how this ripples up to higher level APIs.

Turns out it did.  The socket's makefile() method dup()s the file
descriptor.  Timeouts during select were only being set on the original
socket file descriptor, so any protocols (most text-based ones) which called
conn.makefile() then proceeded use the resulting file object would bomb.

The fix turned out to be surprisingly easy.  Some systems (Windows among
them), didn't have dup(), so makefile() couldn't be implemented in the
straightforward fashion.  A workaround was added to socket.py for those
platforms.  I simply extended the workaround to all platforms.  Now
makefile() returns a file-like object (not a file) which chit-chats directly
through the un-dup()'d socket, and timeouts work as expected.

Skip






More information about the Python-list mailing list