summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2007-06-11 04:52:37 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2007-06-11 04:52:37 (GMT)
commitfdffca27c17876563b06bfe68b352245b2113304 (patch)
tree4b80e0b9e59b14ae639977876c58164077a09a65
parent5c9a81a3d828e775a1500bb8d84dc1dab59513ad (diff)
downloadcpython-fdffca27c17876563b06bfe68b352245b2113304.zip
cpython-fdffca27c17876563b06bfe68b352245b2113304.tar.gz
cpython-fdffca27c17876563b06bfe68b352245b2113304.tar.bz2
Prevent hang if the port cannot be opened.
-rw-r--r--Lib/test/test_urllib2_localnet.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/Lib/test/test_urllib2_localnet.py b/Lib/test/test_urllib2_localnet.py
index ff4349f..05326e9 100644
--- a/Lib/test/test_urllib2_localnet.py
+++ b/Lib/test/test_urllib2_localnet.py
@@ -47,6 +47,7 @@ class LoopbackHttpServerThread(threading.Thread):
self._port = port
self._server_address = ('127.0.0.1', self._port)
self.ready = threading.Event()
+ self.error = None
def stop(self):
"""Stops the webserver if it's currently running."""
@@ -59,12 +60,18 @@ class LoopbackHttpServerThread(threading.Thread):
def run(self):
protocol = "HTTP/1.0"
- self._RequestHandlerClass.protocol_version = protocol
- httpd = LoopbackHttpServer(self._server_address,
- self._RequestHandlerClass)
-
- sa = httpd.socket.getsockname()
- #print "Serving HTTP on", sa[0], "port", sa[1], "..."
+ try:
+ self._RequestHandlerClass.protocol_version = protocol
+ httpd = LoopbackHttpServer(self._server_address,
+ self._RequestHandlerClass)
+
+ sa = httpd.socket.getsockname()
+ #print "Serving HTTP on", sa[0], "port", sa[1], "..."
+ except:
+ # Fail "gracefully" if we are unable to start.
+ self.ready.set()
+ self.error = sys.exc_info()[1]
+ raise
self.ready.set()
while not self._stop:
@@ -241,6 +248,8 @@ class ProxyAuthTests(unittest.TestCase):
self.server = LoopbackHttpServerThread(self.PORT, FakeProxyHandler)
self.server.start()
self.server.ready.wait()
+ if self.server.error:
+ raise self.server.error
handler = urllib2.ProxyHandler({"http" : self.PROXY_URL})
self._digest_auth_handler = urllib2.ProxyDigestAuthHandler()