No way to set a timeout in "urllib".

John Nagle nagle at animats.com
Fri Dec 29 17:04:43 EST 2006


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

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

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

http://mail.python.org/pipermail/python-bugs-list/2003-September/020405.html

    but it was rejected as a feature at

https://sourceforge.net/tracker/?func=detail&atid=105470&aid=803634&group_id=5470

    without anything better going in.  Despite this, current documentation
    recommends that approach:

http://svn.python.org/projects/python/trunk/Doc/howto/urllib2.rst

Someone proposed to fix this

http://mail.python.org/pipermail/python-dev/2006-July/066967.html

    but was discouraged from doing so.

The code was forked by Zope as a workaround in 2003:

    http://pywebsvcs.sourceforge.net/apidocs/wstools/Utility.html

but that's not in the mainstream Python tree.

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

					John Nagle



More information about the Python-list mailing list