Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid the multiprocessing forkserver method in Python 3.14 #3442

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions tests/test_multiprocessing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import multiprocessing
import sys

import pytest
import redis
Expand All @@ -9,9 +8,6 @@

from .conftest import _get_client

if sys.platform == "darwin":
multiprocessing.set_start_method("fork", force=True)


@contextlib.contextmanager
def exit_callback(callback, *args):
Expand All @@ -22,6 +18,16 @@ def exit_callback(callback, *args):


class TestMultiprocessing:
# On macOS and newly non-macOS POSIX systems (since Python 3.14),
# the default method has been changed to forkserver.
# The code in this module does not work with it,
# hence the explicit change to 'fork'
# See https://github.com/python/cpython/issues/125714
if multiprocessing.get_start_method() == "forkserver":
_mp_context = multiprocessing.get_context(method="fork")
else:
_mp_context = multiprocessing.get_context()

# Test connection sharing between forks.
# See issue #1085 for details.

Expand All @@ -45,7 +51,7 @@ def target(conn):
assert conn.read_response() == b"PONG"
conn.disconnect()

proc = multiprocessing.Process(target=target, args=(conn,))
proc = self._mp_context.Process(target=target, args=(conn,))
proc.start()
proc.join(3)
assert proc.exitcode == 0
Expand Down Expand Up @@ -75,7 +81,7 @@ def target(conn, ev):
conn.send_command("ping")

ev = multiprocessing.Event()
proc = multiprocessing.Process(target=target, args=(conn, ev))
proc = self._mp_context.Process(target=target, args=(conn, ev))
proc.start()

conn.disconnect()
Expand Down Expand Up @@ -143,7 +149,7 @@ def target(pool):
assert conn.send_command("ping") is None
assert conn.read_response() == b"PONG"

proc = multiprocessing.Process(target=target, args=(pool,))
proc = self._mp_context.Process(target=target, args=(pool,))
proc.start()
proc.join(3)
assert proc.exitcode == 0
Expand Down Expand Up @@ -181,7 +187,7 @@ def target(pool, disconnect_event):

ev = multiprocessing.Event()

proc = multiprocessing.Process(target=target, args=(pool, ev))
proc = self._mp_context.Process(target=target, args=(pool, ev))
proc.start()

pool.disconnect()
Expand All @@ -197,7 +203,7 @@ def target(client):
assert client.ping() is True
del client

proc = multiprocessing.Process(target=target, args=(r,))
proc = self._mp_context.Process(target=target, args=(r,))
proc.start()
proc.join(3)
assert proc.exitcode == 0
Expand Down
Loading