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