diff options
author | tarek <none@none> | 2009-12-19 22:30:13 +0100 |
---|---|---|
committer | tarek <none@none> | 2009-12-19 22:30:13 +0100 |
commit | b3423443dc7a7b2d524c76959d6dd67013e2165c (patch) | |
tree | ddac03f621e5b91e02559af9491f14c89b851db4 /setuptools/package_index.py | |
parent | a229fc6986028f2d830cdd3223bb2c459dfe8b7f (diff) | |
download | external_python_setuptools-b3423443dc7a7b2d524c76959d6dd67013e2165c.tar.gz external_python_setuptools-b3423443dc7a7b2d524c76959d6dd67013e2165c.tar.bz2 external_python_setuptools-b3423443dc7a7b2d524c76959d6dd67013e2165c.zip |
Introduced a socket timeout of 15 seconds on url openings fixes #48
--HG--
branch : distribute
extra : rebase_source : d4e3831771aa049e71d64f22e315352fa8906dd1
Diffstat (limited to 'setuptools/package_index.py')
-rwxr-xr-x | setuptools/package_index.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index ee980214..924c15e1 100755 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -25,6 +25,8 @@ __all__ = [ 'interpret_distro_name', ] +_SOCKET_TIMEOUT = 15 + def parse_bdist_wininst(name): """Return (base,pyversion) or (None,None) for possible .exe name""" @@ -717,6 +719,17 @@ def htmldecode(text): +def socket_timeout(timeout=15): + def _socket_timeout(func): + def _socket_timeout(*args, **kwargs): + old_timeout = socket.getdefaulttimeout() + socket.setdefaulttimeout(timeout) + try: + return func(*args, **kwargs) + finally: + socket.setdefaulttimeout(old_timeout) + return _socket_timeout + return _socket_timeout def open_with_auth(url): @@ -749,6 +762,8 @@ def open_with_auth(url): return fp +# adding a timeout to avoid freezing package_index +open_with_auth = socket_timeout(_SOCKET_TIMEOUT)(open_with_auth) |