]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-107963: Fix set_forkserver_preload to check the type of given list (#107965)
authorDong-hee Na <donghee.na@python.org>
Tue, 15 Aug 2023 13:58:12 +0000 (22:58 +0900)
committerGitHub <noreply@github.com>
Tue, 15 Aug 2023 13:58:12 +0000 (15:58 +0200)
gh-107963: Fix set_forkserver_preload to check the type of given list

Lib/multiprocessing/forkserver.py
Lib/test/_test_multiprocessing.py
Misc/NEWS.d/next/Library/2023-08-15-18-20-00.gh-issue-107963.20g5BG.rst [new file with mode: 0644]

index 22a911a7a29cdc0219cb46da48fa7e2081abcc83..4642707dae2f4e252554a2f71575289e9064b499 100644 (file)
@@ -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
 
index f881a5d4674699af263328fc3f996c0e6b4543a1..10754964e73bc545279e20827ef84479e4e342d2 100644 (file)
@@ -5369,6 +5369,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 (file)
index 0000000..3a73b2d
--- /dev/null
@@ -0,0 +1,2 @@
+Fix :func:`multiprocessing.set_forkserver_preload` to check the given list
+of modules names. Patch by Dong-hee Na.