mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
Prevent SocketServer.ForkingMixIn from waiting on child processes that it
didn't create, in most cases. When there are max_children handlers running, it will still wait for any child process, not just handler processes.
This commit is contained in:
parent
a6298528e1
commit
392c159ad6
2 changed files with 47 additions and 19 deletions
|
|
@ -2,6 +2,7 @@
|
|||
Test suite for SocketServer.py.
|
||||
"""
|
||||
|
||||
import contextlib
|
||||
import errno
|
||||
import imp
|
||||
import os
|
||||
|
|
@ -82,6 +83,18 @@ class ServerThread(threading.Thread):
|
|||
if verbose: print "thread: done"
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def simple_subprocess(testcase):
|
||||
pid = os.fork()
|
||||
if pid == 0:
|
||||
# Don't throw an exception; it would be caught by the test harness.
|
||||
os._exit(72)
|
||||
yield None
|
||||
pid2, status = os.waitpid(pid, 0)
|
||||
testcase.assertEquals(pid2, pid)
|
||||
testcase.assertEquals(72 << 8, status)
|
||||
|
||||
|
||||
class SocketServerTest(unittest.TestCase):
|
||||
"""Test all socket servers."""
|
||||
|
||||
|
|
@ -183,10 +196,11 @@ class SocketServerTest(unittest.TestCase):
|
|||
self.stream_examine)
|
||||
|
||||
if HAVE_FORKING:
|
||||
def test_ThreadingTCPServer(self):
|
||||
self.run_server(SocketServer.ForkingTCPServer,
|
||||
SocketServer.StreamRequestHandler,
|
||||
self.stream_examine)
|
||||
def test_ForkingTCPServer(self):
|
||||
with simple_subprocess(self):
|
||||
self.run_server(SocketServer.ForkingTCPServer,
|
||||
SocketServer.StreamRequestHandler,
|
||||
self.stream_examine)
|
||||
|
||||
if HAVE_UNIX_SOCKETS:
|
||||
def test_UnixStreamServer(self):
|
||||
|
|
@ -201,9 +215,10 @@ class SocketServerTest(unittest.TestCase):
|
|||
|
||||
if HAVE_FORKING:
|
||||
def test_ForkingUnixStreamServer(self):
|
||||
self.run_server(ForkingUnixStreamServer,
|
||||
SocketServer.StreamRequestHandler,
|
||||
self.stream_examine)
|
||||
with simple_subprocess(self):
|
||||
self.run_server(ForkingUnixStreamServer,
|
||||
SocketServer.StreamRequestHandler,
|
||||
self.stream_examine)
|
||||
|
||||
def test_UDPServer(self):
|
||||
self.run_server(SocketServer.UDPServer,
|
||||
|
|
@ -217,9 +232,10 @@ class SocketServerTest(unittest.TestCase):
|
|||
|
||||
if HAVE_FORKING:
|
||||
def test_ForkingUDPServer(self):
|
||||
self.run_server(SocketServer.ForkingUDPServer,
|
||||
SocketServer.DatagramRequestHandler,
|
||||
self.dgram_examine)
|
||||
with simple_subprocess(self):
|
||||
self.run_server(SocketServer.ForkingUDPServer,
|
||||
SocketServer.DatagramRequestHandler,
|
||||
self.dgram_examine)
|
||||
|
||||
# Alas, on Linux (at least) recvfrom() doesn't return a meaningful
|
||||
# client address so this cannot work:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue