diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-25 22:01:43 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-04-25 22:01:43 (GMT) |
commit | 3bcba8e2889708f646df50953cd45a4f2cf28b02 (patch) | |
tree | 4edf42c36426da21843674f41a170c1e10368877 /Lib/test | |
parent | a23831ff44e0178006a0039d218d60252d5bd755 (diff) | |
download | cpython-3bcba8e2889708f646df50953cd45a4f2cf28b02.zip cpython-3bcba8e2889708f646df50953cd45a4f2cf28b02.tar.gz cpython-3bcba8e2889708f646df50953cd45a4f2cf28b02.tar.bz2 |
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.
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_socketserver.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py index a38e0fd..9578489 100644 --- a/Lib/test/test_socketserver.py +++ b/Lib/test/test_socketserver.py @@ -241,6 +241,31 @@ class SocketServerTest(unittest.TestCase): # socketserver.DatagramRequestHandler, # self.dgram_examine) + @reap_threads + 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(): |