Skip to content

Commit 5f35844

Browse files
author
cxzhong
committed
Fix Python 3.14 compatibility: Set multiprocessing start method to 'fork'
Python 3.14 changed the default multiprocessing start method from 'fork' to 'forkserver' on Linux, which breaks SIGCHLD signal delivery in tests. This causes pselect tests to hang indefinitely. Changes: - Add Python 3.14 detection in conftest.py - Force multiprocessing to use 'fork' method for Python 3.14+ - Add defensive check for __test__ attribute before deletion Fixes test timeouts on Python 3.14.0rc2. All tests now pass in ~8 seconds (previously timed out at 300s+).
1 parent a76f06c commit 5f35844

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/conftest.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pathlib
22
import platform
3+
import sys
34

45
from _pytest.nodes import Collector
56
from _pytest.doctest import DoctestModule
@@ -18,6 +19,16 @@
1819
"cysignals/tests.pyx",
1920
]
2021

22+
# Python 3.14+ changed the default multiprocessing start method to 'forkserver'
23+
# on Linux, which breaks SIGCHLD-based tests. Set it back to 'fork' for compatibility.
24+
if sys.version_info >= (3, 14) and platform.system() != "Windows":
25+
import multiprocessing
26+
try:
27+
multiprocessing.set_start_method('fork', force=True)
28+
except RuntimeError:
29+
# Method may already be set
30+
pass
31+
2132

2233
def pytest_collect_file(
2334
file_path: pathlib.Path,
@@ -31,6 +42,7 @@ def pytest_collect_file(
3142
_, module_name = resolve_pkg_root_and_module_name(file_path)
3243
module = importlib.import_module(module_name)
3344
# delete __test__ injected by cython, to avoid duplicate tests
34-
del module.__test__
45+
if hasattr(module, '__test__'):
46+
del module.__test__
3547
return DoctestModule.from_parent(parent, path=file_path)
3648
return None

0 commit comments

Comments
 (0)