Skip to content

Commit

Permalink
pythongh-107963: Fix set_forkserver_preload to check the type of give…
Browse files Browse the repository at this point in the history
…n list
  • Loading branch information
corona10 committed Aug 15, 2023
1 parent 2e27da1 commit 6d6c6dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/multiprocessing/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _stop_unlocked(self):

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

Expand Down
8 changes: 8 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5369,6 +5369,14 @@ def test_context(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`multiprocessing.set_forkserver_preload` to check the given list
of modules names. Patch by Dong-hee Na.

0 comments on commit 6d6c6dc

Please sign in to comment.