summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-08-15 14:56:53 (GMT)
committerGitHub <noreply@github.com>2023-08-15 14:56:53 (GMT)
commitf0a583b6fbc9a4b2f9358c8426110a5c1f7948a3 (patch)
treed96e7c92cf792f362ceaa4a9a620ad1d71187a8d
parentd189480942348aab345500ac9204965f67f30210 (diff)
downloadcpython-f0a583b6fbc9a4b2f9358c8426110a5c1f7948a3.zip
cpython-f0a583b6fbc9a4b2f9358c8426110a5c1f7948a3.tar.gz
cpython-f0a583b6fbc9a4b2f9358c8426110a5c1f7948a3.tar.bz2
[3.12] gh-107963: Fix set_forkserver_preload to check the type of given list (GH-107965) (#107975)
gh-107963: Fix set_forkserver_preload to check the type of given list (GH-107965) (cherry picked from commit 6515ec3d3d5acd3d0b99c88794bdec09f0831e5b) gh-107963: Fix set_forkserver_preload to check the type of given list Co-authored-by: Dong-hee Na <donghee.na@python.org>
-rw-r--r--Lib/multiprocessing/forkserver.py2
-rw-r--r--Lib/test/_test_multiprocessing.py8
-rw-r--r--Misc/NEWS.d/next/Library/2023-08-15-18-20-00.gh-issue-107963.20g5BG.rst2
3 files changed, 11 insertions, 1 deletions
diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py
index 22a911a..4642707 100644
--- a/Lib/multiprocessing/forkserver.py
+++ b/Lib/multiprocessing/forkserver.py
@@ -61,7 +61,7 @@ class ForkServer(object):
def set_forkserver_preload(self, modules_names):
'''Set list of module names to try to load in forkserver process.'''
- if not all(type(mod) is str for mod in self._preload_modules):
+ if not all(type(mod) is str for mod in modules_names):
raise TypeError('module_names must be a list of strings')
self._preload_modules = modules_names
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index c13b049..4afbe17 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -5331,6 +5331,14 @@ class TestStartMethod(unittest.TestCase):
self.assertRaises(ValueError, ctx.set_start_method, None)
self.check_context(ctx)
+ def test_context_check_module_types(self):
+ try:
+ ctx = multiprocessing.get_context('forkserver')
+ except ValueError:
+ raise unittest.SkipTest('forkserver should be available')
+ with self.assertRaisesRegex(TypeError, 'module_names must be a list of strings'):
+ ctx.set_forkserver_preload([1, 2, 3])
+
def test_set_get(self):
multiprocessing.set_forkserver_preload(PRELOAD)
count = 0
diff --git a/Misc/NEWS.d/next/Library/2023-08-15-18-20-00.gh-issue-107963.20g5BG.rst b/Misc/NEWS.d/next/Library/2023-08-15-18-20-00.gh-issue-107963.20g5BG.rst
new file mode 100644
index 0000000..3a73b2d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-08-15-18-20-00.gh-issue-107963.20g5BG.rst
@@ -0,0 +1,2 @@
+Fix :func:`multiprocessing.set_forkserver_preload` to check the given list
+of modules names. Patch by Dong-hee Na.