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 (pythonGH-107965)

(cherry picked from commit 6515ec3)

Co-authored-by: Dong-hee Na <[email protected]>
pythongh-107963: Fix set_forkserver_preload to check the type of given list
  • Loading branch information
corona10 authored and miss-islington committed Aug 15, 2023
1 parent e2420c5 commit b0dd6b8
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 @@ -5293,6 +5293,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 b0dd6b8

Please sign in to comment.