99
1010from .conftest import _get_client
1111
12- if sys .platform == "darwin" :
13- multiprocessing .set_start_method ("fork" , force = True )
14-
1512
1613@contextlib .contextmanager
1714def exit_callback (callback , * args ):
@@ -22,6 +19,17 @@ def exit_callback(callback, *args):
2219
2320
2421class TestMultiprocessing :
22+
23+ # On macOS and newly non-macOS POSIX systems (since Python 3.14),
24+ # the default method has been changed to forkserver.
25+ # The code in this module does not work with it,
26+ # hence the explicit change to 'fork'
27+ # See https://github.com/python/cpython/issues/125714
28+ if multiprocessing .get_start_method () == 'forkserver' :
29+ _mp_context = multiprocessing .get_context (method = 'fork' )
30+ else :
31+ _mp_context = multiprocessing .get_context ()
32+
2533 # Test connection sharing between forks.
2634 # See issue #1085 for details.
2735
@@ -45,7 +53,7 @@ def target(conn):
4553 assert conn .read_response () == b"PONG"
4654 conn .disconnect ()
4755
48- proc = multiprocessing .Process (target = target , args = (conn ,))
56+ proc = self . _mp_context .Process (target = target , args = (conn ,))
4957 proc .start ()
5058 proc .join (3 )
5159 assert proc .exitcode == 0
@@ -75,7 +83,7 @@ def target(conn, ev):
7583 conn .send_command ("ping" )
7684
7785 ev = multiprocessing .Event ()
78- proc = multiprocessing .Process (target = target , args = (conn , ev ))
86+ proc = self . _mp_context .Process (target = target , args = (conn , ev ))
7987 proc .start ()
8088
8189 conn .disconnect ()
@@ -143,7 +151,7 @@ def target(pool):
143151 assert conn .send_command ("ping" ) is None
144152 assert conn .read_response () == b"PONG"
145153
146- proc = multiprocessing .Process (target = target , args = (pool ,))
154+ proc = self . _mp_context .Process (target = target , args = (pool ,))
147155 proc .start ()
148156 proc .join (3 )
149157 assert proc .exitcode == 0
@@ -181,7 +189,7 @@ def target(pool, disconnect_event):
181189
182190 ev = multiprocessing .Event ()
183191
184- proc = multiprocessing .Process (target = target , args = (pool , ev ))
192+ proc = self . _mp_context .Process (target = target , args = (pool , ev ))
185193 proc .start ()
186194
187195 pool .disconnect ()
@@ -197,7 +205,7 @@ def target(client):
197205 assert client .ping () is True
198206 del client
199207
200- proc = multiprocessing .Process (target = target , args = (r ,))
208+ proc = self . _mp_context .Process (target = target , args = (r ,))
201209 proc .start ()
202210 proc .join (3 )
203211 assert proc .exitcode == 0
0 commit comments