mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
GH-84559: Deprecate fork being the multiprocessing default. (#100618)
This starts the process. Users who don't specify their own start method and use the default on platforms where it is 'fork' will see a DeprecationWarning upon multiprocessing.Pool() construction or upon multiprocessing.Process.start() or concurrent.futures.ProcessPool use. See the related issue and documentation within this change for details.
This commit is contained in:
parent
618b7a8260
commit
0ca67e6313
16 changed files with 284 additions and 63 deletions
|
@ -18,6 +18,7 @@ import sys
|
|||
import threading
|
||||
import time
|
||||
import unittest
|
||||
import warnings
|
||||
import weakref
|
||||
from pickle import PicklingError
|
||||
|
||||
|
@ -571,6 +572,24 @@ class ProcessPoolShutdownTest(ExecutorShutdownTest):
|
|||
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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue