aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_socketserver.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-25 22:26:08 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-25 22:26:08 +0000
commite3123915297da3e87f6d62c0e0788a6b5421a5cf (patch)
treef29aeb87761b4ba6b87b9cfbc99b6bbbececee44 /Lib/test/test_socketserver.py
parentd5781076ebff95e4d1a7054d77fb87041675baf1 (diff)
downloadcpython-e3123915297da3e87f6d62c0e0788a6b5421a5cf.tar.gz
cpython-e3123915297da3e87f6d62c0e0788a6b5421a5cf.zip
Merged revisions 80487,80489 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r80487 | antoine.pitrou | 2010-04-26 00:01:43 +0200 (lun., 26 avril 2010) | 12 lines Merged revisions 80484 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80484 | antoine.pitrou | 2010-04-25 23:40:32 +0200 (dim., 25 avril 2010) | 6 lines Issue #2302: Fix a race condition in SocketServer.BaseServer.shutdown, where the method could block indefinitely if called just before the event loop started running. This also fixes the occasional freezes witnessed in test_httpservers. ........ ................ r80489 | antoine.pitrou | 2010-04-26 00:19:43 +0200 (lun., 26 avril 2010) | 9 lines Merged revisions 80480 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r80480 | antoine.pitrou | 2010-04-25 23:15:50 +0200 (dim., 25 avril 2010) | 3 lines Replace a Lock with a better suited Event. ........ ................
Diffstat (limited to 'Lib/test/test_socketserver.py')
-rw-r--r--Lib/test/test_socketserver.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index 43ce55c37ab..0ab95d18d3e 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -243,6 +243,30 @@ class SocketServerTest(unittest.TestCase):
# socketserver.DatagramRequestHandler,
# self.dgram_examine)
+ def test_shutdown(self):
+ # Issue #2302: shutdown() should always succeed in making an
+ # other thread leave serve_forever().
+ class MyServer(socketserver.TCPServer):
+ pass
+
+ class MyHandler(socketserver.StreamRequestHandler):
+ pass
+
+ threads = []
+ for i in range(20):
+ s = MyServer((HOST, 0), MyHandler)
+ t = threading.Thread(
+ name='MyServer serving',
+ target=s.serve_forever,
+ kwargs={'poll_interval':0.01})
+ t.daemon = True # In case this function raises.
+ threads.append((t, s))
+ for t, s in threads:
+ t.start()
+ s.shutdown()
+ for t, s in threads:
+ t.join()
+
def test_main():
if imp.lock_held():