[2.7] bpo-31593: test_socketserver waits child processes by vstinner · Pull Request #3786 · python/cpython
Expand Up
@@ -69,6 +69,20 @@ def simple_subprocess(testcase):
testcase.assertEqual(72 << 8, status)
def close_server(server): server.server_close()
if hasattr(server, 'active_children'): # ForkingMixIn: Manually reap all child processes, since server_close() # calls waitpid() in non-blocking mode using the WNOHANG flag. for pid in server.active_children.copy(): try: os.waitpid(pid, 0) except ChildProcessError: pass server.active_children.clear()
@unittest.skipUnless(threading, 'Threading required for this test.') class SocketServerTest(unittest.TestCase): """Test all socket servers.""" Expand Down Expand Up @@ -118,7 +132,7 @@ def make_server(self, addr, svrcls, hdlrbase): class MyServer(svrcls): def handle_error(self, request, client_address): self.close_request(request) self.server_close() close_server(self) raise
class MyHandler(hdlrbase): Expand Down Expand Up @@ -158,7 +172,7 @@ def run_server(self, svrcls, hdlrbase, testfunc): if verbose: print "waiting for server" server.shutdown() t.join() server.server_close() close_server(server) self.assertRaises(socket.error, server.socket.fileno) if verbose: print "done"
Expand Down Expand Up @@ -314,6 +328,7 @@ class MyHandler(SocketServer.StreamRequestHandler): s.shutdown() for t, s in threads: t.join() close_server(s)
def test_tcpserver_bind_leak(self): # Issue #22435: the server socket wouldn't be closed if bind()/listen() Expand Down Expand Up @@ -347,7 +362,7 @@ def shutdown_request(self, request): s.close() server.handle_request() self.assertEqual(server.shutdown_called, 1) server.server_close() close_server(server)
def test_main(): Expand Down
def close_server(server): server.server_close()
if hasattr(server, 'active_children'): # ForkingMixIn: Manually reap all child processes, since server_close() # calls waitpid() in non-blocking mode using the WNOHANG flag. for pid in server.active_children.copy(): try: os.waitpid(pid, 0) except ChildProcessError: pass server.active_children.clear()
@unittest.skipUnless(threading, 'Threading required for this test.') class SocketServerTest(unittest.TestCase): """Test all socket servers.""" Expand Down Expand Up @@ -118,7 +132,7 @@ def make_server(self, addr, svrcls, hdlrbase): class MyServer(svrcls): def handle_error(self, request, client_address): self.close_request(request) self.server_close() close_server(self) raise
class MyHandler(hdlrbase): Expand Down Expand Up @@ -158,7 +172,7 @@ def run_server(self, svrcls, hdlrbase, testfunc): if verbose: print "waiting for server" server.shutdown() t.join() server.server_close() close_server(server) self.assertRaises(socket.error, server.socket.fileno) if verbose: print "done"
Expand Down Expand Up @@ -314,6 +328,7 @@ class MyHandler(SocketServer.StreamRequestHandler): s.shutdown() for t, s in threads: t.join() close_server(s)
def test_tcpserver_bind_leak(self): # Issue #22435: the server socket wouldn't be closed if bind()/listen() Expand Down Expand Up @@ -347,7 +362,7 @@ def shutdown_request(self, request): s.close() server.handle_request() self.assertEqual(server.shutdown_called, 1) server.server_close() close_server(server)
def test_main(): Expand Down