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

Commitd4c410f

Browse files
authored
gh-84559: Remove the new multiprocessing warning, too disruptive. (#101551)
This reverts the core of#100618 while leaving relevant documentationimprovements and minor refactorings in place.
1 parentf6c53b8 commitd4c410f

File tree

11 files changed

+27
-189
lines changed

11 files changed

+27
-189
lines changed

‎Doc/library/concurrent.futures.rst‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,18 @@ to a :class:`ProcessPoolExecutor` will result in deadlock.
281281

282282
Added the *initializer* and *initargs* arguments.
283283

284+
..note::
285+
The default:mod:`multiprocessing` start method
286+
(see:ref:`multiprocessing-start-methods`) will change away from
287+
*fork* in Python 3.14. Code that requires *fork* be used for their
288+
:class:`ProcessPoolExecutor` should explicitly specify that by
289+
passing a ``mp_context=multiprocessing.get_context("fork")``
290+
parameter.
291+
284292
..versionchanged::3.11
285293
The *max_tasks_per_child* argument was added to allow users to
286294
control the lifetime of workers in the pool.
287295

288-
..versionchanged::3.12
289-
The implicit use of the:mod:`multiprocessing` *fork* start method as a
290-
platform default (see:ref:`multiprocessing-start-methods`) now raises a
291-
:exc:`DeprecationWarning`. The default will change in Python 3.14.
292-
Code that requires *fork* should explicitly specify that when creating
293-
their:class:`ProcessPoolExecutor` by passing a
294-
``mp_context=multiprocessing.get_context('fork')`` parameter.
295-
296296
.. _processpoolexecutor-example:
297297

298298
ProcessPoolExecutor Example

‎Doc/library/multiprocessing.rst‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ to start a process. These *start methods* are
126126

127127
Available on POSIX systems. Currently the default on POSIX except macOS.
128128

129+
..note::
130+
The default start method will change away from *fork* in Python 3.14.
131+
Code that requires *fork* should explicitly specify that via
132+
:func:`get_context` or:func:`set_start_method`.
133+
129134
*forkserver*
130135
When the program starts and selects the *forkserver* start method,
131136
a server process is spawned. From then on, whenever a new process
@@ -138,11 +143,6 @@ to start a process. These *start methods* are
138143
Available on POSIX platforms which support passing file descriptors
139144
over Unix pipes such as Linux.
140145

141-
..versionchanged::3.12
142-
Implicit use of the *fork* start method as the default now raises a
143-
:exc:`DeprecationWarning`. Code that requires it should explicitly
144-
specify *fork* via:func:`get_context` or:func:`set_start_method`.
145-
The default will change away from *fork* in 3.14.
146146

147147
..versionchanged::3.8
148148

@@ -1107,6 +1107,7 @@ Miscellaneous
11071107
launched (before creating a:class:`Pool` or starting a:class:`Process`).
11081108

11091109
Only meaningful when using the ``'forkserver'`` start method.
1110+
See:ref:`multiprocessing-start-methods`.
11101111

11111112
..versionadded::3.4
11121113

‎Doc/whatsnew/3.12.rst‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,6 @@ Deprecated
440440
warning at compile time. This field will be removed in Python 3.14.
441441
(Contributed by Ramvikrams and Kumar Aditya in:gh:`101193`. PEP by Ken Jin.)
442442

443-
* Use of the implicit default ``'fork'`` start method for
444-
:mod:`multiprocessing` and:class:`concurrent.futures.ProcessPoolExecutor`
445-
now emits a:exc:`DeprecationWarning` on Linux and other non-macOS POSIX
446-
systems. Avoid this by explicitly specifying a start method.
447-
See:ref:`multiprocessing-start-methods`.
448-
449443
Pending Removal in Python 3.13
450444
------------------------------
451445

@@ -510,9 +504,13 @@ Pending Removal in Python 3.14
510504
* Testing the truth value of an:class:`xml.etree.ElementTree.Element`
511505
is deprecated and will raise an exception in Python 3.14.
512506

513-
* The default:mod:`multiprocessing` start method will change to one of either
514-
``'forkserver'`` or ``'spawn'`` on all platforms for which ``'fork'`` remains
515-
the default per:gh:`84559`.
507+
* The default:mod:`multiprocessing` start method will change to a safer one on
508+
Linux, BSDs, and other non-macOS POSIX platforms where ``'fork'`` is currently
509+
the default (:gh:`84559`). Adding a runtime warning about this was deemed too
510+
disruptive as the majority of code is not expected to care. Use the
511+
:func:`~multiprocessing.get_context` or
512+
:func:`~multiprocessing.set_start_method` APIs to explicitly specify when
513+
your code *requires* ``'fork'``. See:ref:`multiprocessing-start-methods`.
516514

517515
Pending Removal in Future Versions
518516
----------------------------------

‎Lib/concurrent/futures/process.py‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
importitertools
5858
importsys
5959
fromtracebackimportformat_exception
60-
importwarnings
6160

6261

6362
_threads_wakeups=weakref.WeakKeyDictionary()
@@ -651,22 +650,6 @@ def __init__(self, max_workers=None, mp_context=None,
651650
mp_context=mp.get_context("spawn")
652651
else:
653652
mp_context=mp.get_context()
654-
if (mp_context.get_start_method()=="fork"and
655-
mp_context==mp.context._default_context._default_context):
656-
warnings.warn(
657-
"The default multiprocessing start method will change "
658-
"away from 'fork' in Python >= 3.14, per GH-84559. "
659-
"ProcessPoolExecutor uses multiprocessing. "
660-
"If your application requires the 'fork' multiprocessing "
661-
"start method, explicitly specify that by passing a "
662-
"mp_context= parameter. "
663-
"The safest start method is 'spawn'.",
664-
category=mp.context.DefaultForkDeprecationWarning,
665-
stacklevel=2,
666-
)
667-
# Avoid the equivalent warning from multiprocessing itself via
668-
# a non-default fork context.
669-
mp_context=mp.get_context("fork")
670653
self._mp_context=mp_context
671654

672655
# https://github.com/python/cpython/issues/90622

‎Lib/multiprocessing/context.py‎

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class TimeoutError(ProcessError):
2323
classAuthenticationError(ProcessError):
2424
pass
2525

26-
classDefaultForkDeprecationWarning(DeprecationWarning):
27-
pass
28-
2926
#
3027
# Base type for contexts. Bound methods of an instance of this type are included in __all__ of __init__.py
3128
#
@@ -284,23 +281,6 @@ def _Popen(process_obj):
284281
from .popen_forkimportPopen
285282
returnPopen(process_obj)
286283

287-
_warn_package_prefixes= (os.path.dirname(__file__),)
288-
289-
class_DeprecatedForkProcess(ForkProcess):
290-
@classmethod
291-
def_Popen(cls,process_obj):
292-
importwarnings
293-
warnings.warn(
294-
"The default multiprocessing start method will change "
295-
"away from 'fork' in Python >= 3.14, per GH-84559. "
296-
"Use multiprocessing.get_context(X) or .set_start_method(X) to "
297-
"explicitly specify it when your application requires 'fork'. "
298-
"The safest start method is 'spawn'.",
299-
category=DefaultForkDeprecationWarning,
300-
skip_file_prefixes=_warn_package_prefixes,
301-
)
302-
returnsuper()._Popen(process_obj)
303-
304284
classSpawnProcess(process.BaseProcess):
305285
_start_method='spawn'
306286
@staticmethod
@@ -324,9 +304,6 @@ class ForkContext(BaseContext):
324304
_name='fork'
325305
Process=ForkProcess
326306

327-
class_DefaultForkContext(ForkContext):
328-
Process=_DeprecatedForkProcess
329-
330307
classSpawnContext(BaseContext):
331308
_name='spawn'
332309
Process=SpawnProcess
@@ -342,16 +319,13 @@ def _check_available(self):
342319
'fork':ForkContext(),
343320
'spawn':SpawnContext(),
344321
'forkserver':ForkServerContext(),
345-
# Remove None and _DefaultForkContext() when changing the default
346-
# in 3.14 for https://github.com/python/cpython/issues/84559.
347-
None:_DefaultForkContext(),
348322
}
349323
ifsys.platform=='darwin':
350324
# bpo-33725: running arbitrary code after fork() is no longer reliable
351325
# on macOS since macOS 10.14 (Mojave). Use spawn by default instead.
352326
_default_context=DefaultContext(_concrete_contexts['spawn'])
353327
else:
354-
_default_context=DefaultContext(_concrete_contexts[None])
328+
_default_context=DefaultContext(_concrete_contexts['fork'])
355329

356330
else:
357331

‎Lib/test/_test_multiprocessing.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,10 +4098,9 @@ def test_shared_memory_SharedMemoryServer_ignores_sigint(self):
40984098
deftest_shared_memory_SharedMemoryManager_reuses_resource_tracker(self):
40994099
# bpo-36867: test that a SharedMemoryManager uses the
41004100
# same resource_tracker process as its parent.
4101-
cmd=f'''if 1:
4101+
cmd='''if 1:
41024102
from multiprocessing.managers import SharedMemoryManager
4103-
from multiprocessing import set_start_method
4104-
set_start_method({multiprocessing.get_start_method()!r})
4103+
41054104
41064105
smm = SharedMemoryManager()
41074106
smm.start()

‎Lib/test/test_concurrent_futures.py‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
importthreading
1919
importtime
2020
importunittest
21-
importwarnings
2221
importweakref
2322
frompickleimportPicklingError
2423

@@ -572,24 +571,6 @@ def test_shutdown_no_wait(self):
572571
assertall([r==abs(v)forr,vinzip(res,range(-5,5))])
573572

574573

575-
@unittest.skipIf(mp.get_all_start_methods()[0]!="fork","non-fork default.")
576-
classProcessPoolExecutorDefaultForkWarning(unittest.TestCase):
577-
deftest_fork_default_warns(self):
578-
withself.assertWarns(mp.context.DefaultForkDeprecationWarning):
579-
withfutures.ProcessPoolExecutor(2):
580-
pass
581-
582-
deftest_explicit_fork_does_not_warn(self):
583-
withwarnings.catch_warnings(record=True)asws:
584-
warnings.simplefilter("ignore")
585-
warnings.filterwarnings(
586-
'always',category=mp.context.DefaultForkDeprecationWarning)
587-
ctx=mp.get_context("fork")# Non-default fork context.
588-
withfutures.ProcessPoolExecutor(2,mp_context=ctx):
589-
pass
590-
self.assertEqual(len(ws),0,msg=[str(x)forxinws])
591-
592-
593574
create_executor_tests(ProcessPoolShutdownTest,
594575
executor_mixins=(ProcessPoolForkMixin,
595576
ProcessPoolForkserverMixin,

‎Lib/test/test_logging.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4759,9 +4759,8 @@ def test_multiprocessing(self):
47594759
# In other processes, processName is correct when multiprocessing in imported,
47604760
# but it is (incorrectly) defaulted to 'MainProcess' otherwise (bpo-38762).
47614761
importmultiprocessing
4762-
mp=multiprocessing.get_context('spawn')
4763-
parent_conn,child_conn=mp.Pipe()
4764-
p=mp.Process(
4762+
parent_conn,child_conn=multiprocessing.Pipe()
4763+
p=multiprocessing.Process(
47654764
target=self._extract_logrecord_process_name,
47664765
args=(2,LOG_MULTI_PROCESSING,child_conn,)
47674766
)

‎Lib/test/test_multiprocessing_defaults.py‎

Lines changed: 0 additions & 85 deletions
This file was deleted.

‎Lib/test/test_re.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,8 +2431,7 @@ def test_regression_gh94675(self):
24312431
input_js='''a(function() {
24322432
///////////////////////////////////////////////////////////////////
24332433
});'''
2434-
mp=multiprocessing.get_context('spawn')
2435-
p=mp.Process(target=pattern.sub,args=('',input_js))
2434+
p=multiprocessing.Process(target=pattern.sub,args=('',input_js))
24362435
p.start()
24372436
p.join(SHORT_TIMEOUT)
24382437
try:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp