summaryrefslogtreecommitdiff
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorAntoine Pitrou <pitrou@free.fr>2017-07-22 13:22:54 +0200
committerGitHub <noreply@github.com>2017-07-22 13:22:54 +0200
commit896145d9d266ee2758cfcd7691238cbc1f9e1ab8 (patch)
tree3b36a7020108c7305a478e174d8a73cdd6deb540 /Lib/test/_test_multiprocessing.py
parent616ecf18f3aacbd8d172e01673877b22fe946e54 (diff)
downloadcpython-git-896145d9d266ee2758cfcd7691238cbc1f9e1ab8.tar.gz
bpo-26732: fix too many fds in processes started with the "forkserver" method (#2813)
* bpo-26732: fix too many fds in processes started with the "forkserver" method A child process would inherit as many fds as the number of still-running children. * Add blurb and test comment
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 329a6d29ac..a14fa7422e 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -494,6 +494,40 @@ class _TestProcess(BaseTestCase):
self.assertIs(wr(), None)
self.assertEqual(q.get(), 5)
+ @classmethod
+ def _test_child_fd_inflation(self, evt, q):
+ q.put(test.support.fd_count())
+ evt.wait()
+
+ def test_child_fd_inflation(self):
+ # Number of fds in child processes should not grow with the
+ # number of running children.
+ if self.TYPE == 'threads':
+ self.skipTest('test not appropriate for {}'.format(self.TYPE))
+
+ sm = multiprocessing.get_start_method()
+ if sm == 'fork':
+ # The fork method by design inherits all fds from the parent,
+ # trying to go against it is a lost battle
+ self.skipTest('test not appropriate for {}'.format(sm))
+
+ N = 5
+ evt = self.Event()
+ q = self.Queue()
+
+ procs = [self.Process(target=self._test_child_fd_inflation, args=(evt, q))
+ for i in range(N)]
+ for p in procs:
+ p.start()
+
+ try:
+ fd_counts = [q.get() for i in range(N)]
+ self.assertEqual(len(set(fd_counts)), 1, fd_counts)
+
+ finally:
+ evt.set()
+ for p in procs:
+ p.join()
#
#