Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc2202a7

Browse files
authored
gh-109263: Start process from spawn context in multiprocessing no longer have side effect (GH-135813)
1 parent450e836 commitc2202a7

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

‎Lib/multiprocessing/spawn.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def get_preparation_data(name):
184184
sys_argv=sys.argv,
185185
orig_dir=process.ORIGINAL_DIR,
186186
dir=os.getcwd(),
187-
start_method=get_start_method(),
187+
start_method=get_start_method(allow_none=True),
188188
)
189189

190190
# Figure out whether to initialise main in the subprocess as a module

‎Lib/test/_test_multiprocessing.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5967,6 +5967,26 @@ def test_context(self):
59675967
self.assertRaises(ValueError,ctx.set_start_method,None)
59685968
self.check_context(ctx)
59695969

5970+
@staticmethod
5971+
def_dummy_func():
5972+
pass
5973+
5974+
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
5975+
deftest_spawn_dont_set_context(self):
5976+
# Run a process with spawn or forkserver context may change
5977+
# the global start method, see gh-109263.
5978+
formethodin ('fork','spawn','forkserver'):
5979+
multiprocessing.set_start_method(None,force=True)
5980+
5981+
try:
5982+
ctx=multiprocessing.get_context(method)
5983+
exceptValueError:
5984+
continue
5985+
process=ctx.Process(target=self._dummy_func)
5986+
process.start()
5987+
process.join()
5988+
self.assertIsNone(multiprocessing.get_start_method(allow_none=True))
5989+
59705990
deftest_context_check_module_types(self):
59715991
try:
59725992
ctx=multiprocessing.get_context('forkserver')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Starting a process from spawn context in:mod:`multiprocessing` no longer
2+
sets the start method globally.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp