Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup messages, test futures warning.
  • Loading branch information
gpshead committed Dec 31, 2022
commit c52b9dba4c06e7bc51f62fe44bbe0de243a30b8f
19 changes: 8 additions & 11 deletions Lib/concurrent/futures/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,16 @@ def __init__(self, max_workers=None, mp_context=None,
mp_context = mp.get_context("spawn")
else:
mp_context = mp.get_context()
# getattr(...)() instead of .get_start_method() as the docs imply that
# this method is not required. Hokey! But if someone passed us an odd
# duck, we just skip our introspection and warning.
if (getattr(mp_context, "get_start_method", lambda: None)() == "fork"
and mp_context == mp.context._default_context._default_context):
if (mp_context.get_start_method() == "fork" and
mp_context == mp.context._default_context._default_context):
import warnings
warnings.warn(
"The multiprocessing 'fork' start method will change "
"away from 'fork' in Python >= 3.14, per GH-84559. "
"concurrent.futures.process is built upon multiprocessing. "
"If your application requires continued use of 'fork', "
"pass a mp_context= parameter created with the start method "
"explicitly specified.",
"The default multiprocessing start method will change "
"away from 'fork' in Python >= 3.14, per GH-84559. "
"ProcessPoolExecutor uses multiprocessing. "
"If your application requires 'fork', explicitly specify "
"that by passing a mp_context= parameter. "
"The safest start method is 'spawn'.",
category=mp.context.DefaultForkDeprecationWarning,
stacklevel=2,
)
Expand Down
10 changes: 5 additions & 5 deletions Lib/multiprocessing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ class _DeprecatedForkProcess(ForkProcess):
def _warn(stacklevel):
import warnings
warnings.warn(
"The multiprocessing 'fork' start method will change "
"change away from 'fork' in Python >= 3.14, per GH-84559. "
"Use a multiprocessing.get_context(X) context or "
"call multiprocessing.set_start_method(X) to explicitly "
"specify your application's need if you really want 'fork'.",
"The default multiprocessing start method will change "
"away from 'fork' in Python >= 3.14, per GH-84559. "
"Use multiprocessing.get_context(X) or .set_start_method(X) to "
"explicitly specify it when your application requires 'fork'. "
"The safest start method is 'spawn'.",
category=DefaultForkDeprecationWarning,
stacklevel=stacklevel,
)
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_concurrent_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import threading
import time
import unittest
import warnings
import weakref
from pickle import PicklingError

Expand Down Expand Up @@ -571,6 +572,24 @@ def test_shutdown_no_wait(self):
assert all([r == abs(v) for r, v in zip(res, range(-5, 5))])


@unittest.skipIf(mp.get_all_start_methods()[0] != "fork", "non-fork default.")
class ProcessPoolExecutorDefaultForkWarning(unittest.TestCase):
def test_fork_default_warns(self):
with self.assertWarns(mp.context.DefaultForkDeprecationWarning):
with futures.ProcessPoolExecutor(2):
pass

def test_explicit_fork_does_not_warn(self):
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("ignore")
warnings.filterwarnings(
'always', category=mp.context.DefaultForkDeprecationWarning)
ctx = mp.get_context("fork") # Non-default fork context.
with futures.ProcessPoolExecutor(2, mp_context=ctx):
pass
self.assertEqual(len(ws), 0, msg=[str(x) for x in ws])


create_executor_tests(ProcessPoolShutdownTest,
executor_mixins=(ProcessPoolForkMixin,
ProcessPoolForkserverMixin,
Expand Down