Skip to content

Commit db4400b

Browse files
[3.11] pythongh-107963: Fix set_forkserver_preload to check the type of given list (pythonGH-107965) (pythongh-107976)
pythongh-107963: Fix set_forkserver_preload to check the type of given list (pythonGH-107965) (cherry picked from commit 6515ec3) pythongh-107963: Fix set_forkserver_preload to check the type of given list Co-authored-by: Dong-hee Na <[email protected]>
1 parent e2420c5 commit db4400b

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Lib/multiprocessing/forkserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _stop_unlocked(self):
6161

6262
def set_forkserver_preload(self, modules_names):
6363
'''Set list of module names to try to load in forkserver process.'''
64-
if not all(type(mod) is str for mod in self._preload_modules):
64+
if not all(type(mod) is str for mod in modules_names):
6565
raise TypeError('module_names must be a list of strings')
6666
self._preload_modules = modules_names
6767

Lib/test/_test_multiprocessing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,14 @@ def test_context(self):
52935293
self.assertRaises(ValueError, ctx.set_start_method, None)
52945294
self.check_context(ctx)
52955295

5296+
def test_context_check_module_types(self):
5297+
try:
5298+
ctx = multiprocessing.get_context('forkserver')
5299+
except ValueError:
5300+
raise unittest.SkipTest('forkserver should be available')
5301+
with self.assertRaisesRegex(TypeError, 'module_names must be a list of strings'):
5302+
ctx.set_forkserver_preload([1, 2, 3])
5303+
52965304
def test_set_get(self):
52975305
multiprocessing.set_forkserver_preload(PRELOAD)
52985306
count = 0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix :func:`multiprocessing.set_forkserver_preload` to check the given list
2+
of modules names. Patch by Dong-hee Na.

0 commit comments

Comments
 (0)