11import contextlib
22import multiprocessing
3- import sys
43
54import pytest
65import redis
98
109from .conftest import _get_client
1110
12- if sys .platform == "darwin" :
13- multiprocessing .set_start_method ("fork" , force = True )
14-
1511
1612@contextlib .contextmanager
1713def exit_callback (callback , * args ):
@@ -22,6 +18,17 @@ def exit_callback(callback, *args):
2218
2319
2420class TestMultiprocessing :
21+
22+ # On macOS and newly non-macOS POSIX systems (since Python 3.14),
23+ # the default method has been changed to forkserver.
24+ # The code in this module does not work with it,
25+ # hence the explicit change to 'fork'
26+ # See https://github.com/python/cpython/issues/125714
27+ if multiprocessing .get_start_method () == "forkserver" :
28+ _mp_context = multiprocessing .get_context (method = "fork" )
29+ else :
30+ _mp_context = multiprocessing .get_context ()
31+
2532 # Test connection sharing between forks.
2633 # See issue #1085 for details.
2734
@@ -45,7 +52,7 @@ def target(conn):
4552 assert conn .read_response () == b"PONG"
4653 conn .disconnect ()
4754
48- proc = multiprocessing .Process (target = target , args = (conn ,))
55+ proc = self . _mp_context .Process (target = target , args = (conn ,))
4956 proc .start ()
5057 proc .join (3 )
5158 assert proc .exitcode == 0
@@ -75,7 +82,7 @@ def target(conn, ev):
7582 conn .send_command ("ping" )
7683
7784 ev = multiprocessing .Event ()
78- proc = multiprocessing .Process (target = target , args = (conn , ev ))
85+ proc = self . _mp_context .Process (target = target , args = (conn , ev ))
7986 proc .start ()
8087
8188 conn .disconnect ()
@@ -143,7 +150,7 @@ def target(pool):
143150 assert conn .send_command ("ping" ) is None
144151 assert conn .read_response () == b"PONG"
145152
146- proc = multiprocessing .Process (target = target , args = (pool ,))
153+ proc = self . _mp_context .Process (target = target , args = (pool ,))
147154 proc .start ()
148155 proc .join (3 )
149156 assert proc .exitcode == 0
@@ -181,7 +188,7 @@ def target(pool, disconnect_event):
181188
182189 ev = multiprocessing .Event ()
183190
184- proc = multiprocessing .Process (target = target , args = (pool , ev ))
191+ proc = self . _mp_context .Process (target = target , args = (pool , ev ))
185192 proc .start ()
186193
187194 pool .disconnect ()
@@ -197,7 +204,7 @@ def target(client):
197204 assert client .ping () is True
198205 del client
199206
200- proc = multiprocessing .Process (target = target , args = (r ,))
207+ proc = self . _mp_context .Process (target = target , args = (r ,))
201208 proc .start ()
202209 proc .join (3 )
203210 assert proc .exitcode == 0
0 commit comments