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,16 @@ def exit_callback(callback, *args):
2218
2319
2420class TestMultiprocessing :
21+ # On macOS and newly non-macOS POSIX systems (since Python 3.14),
22+ # the default method has been changed to forkserver.
23+ # The code in this module does not work with it,
24+ # hence the explicit change to 'fork'
25+ # See https://github.com/python/cpython/issues/125714
26+ if multiprocessing .get_start_method () == "forkserver" :
27+ _mp_context = multiprocessing .get_context (method = "fork" )
28+ else :
29+ _mp_context = multiprocessing .get_context ()
30+
2531 # Test connection sharing between forks.
2632 # See issue #1085 for details.
2733
@@ -45,7 +51,7 @@ def target(conn):
4551 assert conn .read_response () == b"PONG"
4652 conn .disconnect ()
4753
48- proc = multiprocessing .Process (target = target , args = (conn ,))
54+ proc = self . _mp_context .Process (target = target , args = (conn ,))
4955 proc .start ()
5056 proc .join (3 )
5157 assert proc .exitcode == 0
@@ -75,7 +81,7 @@ def target(conn, ev):
7581 conn .send_command ("ping" )
7682
7783 ev = multiprocessing .Event ()
78- proc = multiprocessing .Process (target = target , args = (conn , ev ))
84+ proc = self . _mp_context .Process (target = target , args = (conn , ev ))
7985 proc .start ()
8086
8187 conn .disconnect ()
@@ -143,7 +149,7 @@ def target(pool):
143149 assert conn .send_command ("ping" ) is None
144150 assert conn .read_response () == b"PONG"
145151
146- proc = multiprocessing .Process (target = target , args = (pool ,))
152+ proc = self . _mp_context .Process (target = target , args = (pool ,))
147153 proc .start ()
148154 proc .join (3 )
149155 assert proc .exitcode == 0
@@ -181,7 +187,7 @@ def target(pool, disconnect_event):
181187
182188 ev = multiprocessing .Event ()
183189
184- proc = multiprocessing .Process (target = target , args = (pool , ev ))
190+ proc = self . _mp_context .Process (target = target , args = (pool , ev ))
185191 proc .start ()
186192
187193 pool .disconnect ()
@@ -197,7 +203,7 @@ def target(client):
197203 assert client .ping () is True
198204 del client
199205
200- proc = multiprocessing .Process (target = target , args = (r ,))
206+ proc = self . _mp_context .Process (target = target , args = (r ,))
201207 proc .start ()
202208 proc .join (3 )
203209 assert proc .exitcode == 0
0 commit comments