summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-04-20 06:54:59 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-04-20 06:54:59 (GMT)
commit281b551a2eecfb9a1ac64274496f7cdeda82662a (patch)
treed240308dd29762880dbd3ad2129c18aee5cb612a
parentac4b7adadf1837cc6bfbca51d815a7b384a4c071 (diff)
downloadcpython-281b551a2eecfb9a1ac64274496f7cdeda82662a.zip
cpython-281b551a2eecfb9a1ac64274496f7cdeda82662a.tar.gz
cpython-281b551a2eecfb9a1ac64274496f7cdeda82662a.tar.bz2
Fix Issue8460: Victor's patch to add timeout in test_urllib2net test_urls.
-rw-r--r--Lib/test/test_urllib2net.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index eaa7154..d2762dc 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -7,6 +7,9 @@ from test.test_urllib2 import sanepathname2url
import socket
import urllib2
import os
+import sys
+
+TIMEOUT = 60 # seconds
def _retry_thrice(func, exc, *args, **kwargs):
@@ -167,18 +170,27 @@ class OtherNetworkTests(unittest.TestCase):
req = expected_err = None
debug(url)
try:
- f = urlopen(url, req)
+ f = urlopen(url, req, TIMEOUT)
except EnvironmentError, err:
debug(err)
if expected_err:
msg = ("Didn't get expected error(s) %s for %s %s, got %s: %s" %
(expected_err, url, req, type(err), err))
self.assertIsInstance(err, expected_err, msg)
+ except urllib2.URLError as err:
+ if isinstance(err[0], socket.timeout):
+ print >>sys.stderr, "<timeout: %s>" % url
+ continue
+ else:
+ raise
else:
- with test_support.transient_internet():
- buf = f.read()
+ try:
+ with test_support.transient_internet():
+ buf = f.read()
+ debug("read %d bytes" % len(buf))
+ except socket.timeout:
+ print >>sys.stderr, "<timeout: %s>" % url
f.close()
- debug("read %d bytes" % len(buf))
debug("******** next url coming up...")
time.sleep(0.1)