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,17 @@ def exit_callback(callback, *args):
22
18
23
19
24
20
class 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
+
25
32
# Test connection sharing between forks.
26
33
# See issue #1085 for details.
27
34
@@ -45,7 +52,7 @@ def target(conn):
45
52
assert conn .read_response () == b"PONG"
46
53
conn .disconnect ()
47
54
48
- proc = multiprocessing .Process (target = target , args = (conn ,))
55
+ proc = self . _mp_context .Process (target = target , args = (conn ,))
49
56
proc .start ()
50
57
proc .join (3 )
51
58
assert proc .exitcode == 0
@@ -75,7 +82,7 @@ def target(conn, ev):
75
82
conn .send_command ("ping" )
76
83
77
84
ev = multiprocessing .Event ()
78
- proc = multiprocessing .Process (target = target , args = (conn , ev ))
85
+ proc = self . _mp_context .Process (target = target , args = (conn , ev ))
79
86
proc .start ()
80
87
81
88
conn .disconnect ()
@@ -143,7 +150,7 @@ def target(pool):
143
150
assert conn .send_command ("ping" ) is None
144
151
assert conn .read_response () == b"PONG"
145
152
146
- proc = multiprocessing .Process (target = target , args = (pool ,))
153
+ proc = self . _mp_context .Process (target = target , args = (pool ,))
147
154
proc .start ()
148
155
proc .join (3 )
149
156
assert proc .exitcode == 0
@@ -181,7 +188,7 @@ def target(pool, disconnect_event):
181
188
182
189
ev = multiprocessing .Event ()
183
190
184
- proc = multiprocessing .Process (target = target , args = (pool , ev ))
191
+ proc = self . _mp_context .Process (target = target , args = (pool , ev ))
185
192
proc .start ()
186
193
187
194
pool .disconnect ()
@@ -197,7 +204,7 @@ def target(client):
197
204
assert client .ping () is True
198
205
del client
199
206
200
- proc = multiprocessing .Process (target = target , args = (r ,))
207
+ proc = self . _mp_context .Process (target = target , args = (r ,))
201
208
proc .start ()
202
209
proc .join (3 )
203
210
assert proc .exitcode == 0
0 commit comments