No way to set a timeout in "urllib".

skip at pobox.com skip at pobox.com
Fri Dec 29 22:14:23 EST 2006


    John> There's no way to set a timeout if you use "urllib" to open a URL.
    John> "HTTP", which "urllib" uses, supports this, but the functionality
    John> is lost at the "urllib" level.

    John>     It's not available via "class URLopener" or "FancyURLopener",
    John>     either.

    John> There is a non-thread-safe workaround from 2003 at

    ...

This topic has come up several times since timeouts were added to socket.
Each time we've asked for a patch that adds timeouts in a rational manner to
all the stuff layered on top of the socket module (httplib, ftplib, etc). As
far as I know it's apparently never been important enough for anyone to rise
to the challenge.  If I remember next spring perhaps I'll submit it as a
possible Google Summer of Code proposal.

    John> The correct fix would probably be to add methods to class
    John> URLopener to control this; that's the usual way of handling
    John> special URL opening situations.

The correct way would be to deal with it at the httplib level, then
percolate it up to urllib2.  Urllib should probably not be extended any
further.

Skip




More information about the Python-list mailing list