aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/_test_multiprocessing.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2023-02-02 15:50:35 -0800
committerGitHub <noreply@github.com>2023-02-02 15:50:35 -0800
commit0ca67e6313c11263ecaef7ce182308eeb5aa6814 (patch)
treeff302df77417456ee4dcf94082b6d942e320b13a /Lib/test/_test_multiprocessing.py
parent618b7a8260bb40290d6551f24885931077309590 (diff)
downloadcpython-0ca67e6313c11263ecaef7ce182308eeb5aa6814.tar.gz
cpython-0ca67e6313c11263ecaef7ce182308eeb5aa6814.zip
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.
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r--Lib/test/_test_multiprocessing.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py
index 2fa75eb4d11..e4a60a4d674 100644
--- a/Lib/test/_test_multiprocessing.py
+++ b/Lib/test/_test_multiprocessing.py
@@ -4098,9 +4098,10 @@ class _TestSharedMemory(BaseTestCase):
def test_shared_memory_SharedMemoryManager_reuses_resource_tracker(self):
# bpo-36867: test that a SharedMemoryManager uses the
# same resource_tracker process as its parent.
- cmd = '''if 1:
+ cmd = f'''if 1:
from multiprocessing.managers import SharedMemoryManager
-
+ from multiprocessing import set_start_method
+ set_start_method({multiprocessing.get_start_method()!r})
smm = SharedMemoryManager()
smm.start()
@@ -4967,11 +4968,13 @@ class TestFlags(unittest.TestCase):
conn.send(tuple(sys.flags))
@classmethod
- def run_in_child(cls):
+ def run_in_child(cls, start_method):
import json
- r, w = multiprocessing.Pipe(duplex=False)
- p = multiprocessing.Process(target=cls.run_in_grandchild, args=(w,))
- p.start()
+ mp = multiprocessing.get_context(start_method)
+ r, w = mp.Pipe(duplex=False)
+ p = mp.Process(target=cls.run_in_grandchild, args=(w,))
+ with warnings.catch_warnings(category=DeprecationWarning):
+ p.start()
grandchild_flags = r.recv()
p.join()
r.close()
@@ -4982,8 +4985,10 @@ class TestFlags(unittest.TestCase):
def test_flags(self):
import json
# start child process using unusual flags
- prog = ('from test._test_multiprocessing import TestFlags; ' +
- 'TestFlags.run_in_child()')
+ prog = (
+ 'from test._test_multiprocessing import TestFlags; '
+ f'TestFlags.run_in_child({multiprocessing.get_start_method()!r})'
+ )
data = subprocess.check_output(
[sys.executable, '-E', '-S', '-O', '-c', prog])
child_flags, grandchild_flags = json.loads(data.decode('ascii'))