9
9
10
10
from .conftest import _get_client
11
11
12
- if sys .platform == "darwin" :
13
- multiprocessing .set_start_method ("fork" , force = True )
14
-
15
12
16
13
@contextlib .contextmanager
17
14
def exit_callback (callback , * args ):
@@ -22,6 +19,17 @@ def exit_callback(callback, *args):
22
19
23
20
24
21
class 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
+
25
33
# Test connection sharing between forks.
26
34
# See issue #1085 for details.
27
35
@@ -45,7 +53,7 @@ def target(conn):
45
53
assert conn .read_response () == b"PONG"
46
54
conn .disconnect ()
47
55
48
- proc = multiprocessing .Process (target = target , args = (conn ,))
56
+ proc = self . _mp_context .Process (target = target , args = (conn ,))
49
57
proc .start ()
50
58
proc .join (3 )
51
59
assert proc .exitcode == 0
@@ -75,7 +83,7 @@ def target(conn, ev):
75
83
conn .send_command ("ping" )
76
84
77
85
ev = multiprocessing .Event ()
78
- proc = multiprocessing .Process (target = target , args = (conn , ev ))
86
+ proc = self . _mp_context .Process (target = target , args = (conn , ev ))
79
87
proc .start ()
80
88
81
89
conn .disconnect ()
@@ -143,7 +151,7 @@ def target(pool):
143
151
assert conn .send_command ("ping" ) is None
144
152
assert conn .read_response () == b"PONG"
145
153
146
- proc = multiprocessing .Process (target = target , args = (pool ,))
154
+ proc = self . _mp_context .Process (target = target , args = (pool ,))
147
155
proc .start ()
148
156
proc .join (3 )
149
157
assert proc .exitcode == 0
@@ -181,7 +189,7 @@ def target(pool, disconnect_event):
181
189
182
190
ev = multiprocessing .Event ()
183
191
184
- proc = multiprocessing .Process (target = target , args = (pool , ev ))
192
+ proc = self . _mp_context .Process (target = target , args = (pool , ev ))
185
193
proc .start ()
186
194
187
195
pool .disconnect ()
@@ -197,7 +205,7 @@ def target(client):
197
205
assert client .ping () is True
198
206
del client
199
207
200
- proc = multiprocessing .Process (target = target , args = (r ,))
208
+ proc = self . _mp_context .Process (target = target , args = (r ,))
201
209
proc .start ()
202
210
proc .join (3 )
203
211
assert proc .exitcode == 0
0 commit comments