Skip to content

Commit 6515ec3

Browse files
authored
gh-107963: Fix set_forkserver_preload to check the type of given list (#107965)
gh-107963: Fix set_forkserver_preload to check the type of given list
1 parent d66bc9e commit 6515ec3

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
@@ -5369,6 +5369,14 @@ def test_context(self):
53695369
self.assertRaises(ValueError, ctx.set_start_method, None)
53705370
self.check_context(ctx)
53715371

5372+
def test_context_check_module_types(self):
5373+
try:
5374+
ctx = multiprocessing.get_context('forkserver')
5375+
except ValueError:
5376+
raise unittest.SkipTest('forkserver should be available')
5377+
with self.assertRaisesRegex(TypeError, 'module_names must be a list of strings'):
5378+
ctx.set_forkserver_preload([1, 2, 3])
5379+
53725380
def test_set_get(self):
53735381
multiprocessing.set_forkserver_preload(PRELOAD)
53745382
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)