From dc9fa75bfa783911e022f8a0b0e494e605502f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 27 Nov 2026 17:23:23 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(probe):=20skip=20the=20child?= =?UTF-8?q?=20fd=20close=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit virtualenv's macOS CI hung in the interpreter probe: the forked child sat in close() inside CPython's close_fds loop before exec, and the parent waited on it until the test timed out. Python opens descriptors non-inheritable, so the probe passes close_fds=False and skips that loop. --- docs/changelog/+probe-close-fds.bugfix.rst | 2 ++ src/python_discovery/_cached_py_info.py | 2 ++ tests/python_discovery/test_cached_py_info.py | 6 ++++++ 3 files changed, 10 insertions(+) create mode 100644 docs/changelog/+probe-close-fds.bugfix.rst diff --git a/docs/changelog/+probe-close-fds.bugfix.rst b/docs/changelog/+probe-close-fds.bugfix.rst new file mode 100644 index 0000000..5a5123a --- /dev/null +++ b/docs/changelog/+probe-close-fds.bugfix.rst @@ -0,0 +1,2 @@ +The interpreter probe no longer hangs on macOS when the forked child blocks closing an inherited file descriptor +before exec. diff --git a/src/python_discovery/_cached_py_info.py b/src/python_discovery/_cached_py_info.py index 503b147..9070c89 100644 --- a/src/python_discovery/_cached_py_info.py +++ b/src/python_discovery/_cached_py_info.py @@ -231,6 +231,8 @@ def _run_subprocess( env=env, encoding="utf-8", errors="backslashreplace", + # on macOS the child's pre-exec close() loop can block forever; Python fds are non-inheritable anyway + close_fds=False, ) out, err, code = _collect_query_output(process, timeout) except OSError as os_error: diff --git a/tests/python_discovery/test_cached_py_info.py b/tests/python_discovery/test_cached_py_info.py index 550b953..c0e120c 100644 --- a/tests/python_discovery/test_cached_py_info.py +++ b/tests/python_discovery/test_cached_py_info.py @@ -85,6 +85,12 @@ def test_run_subprocess_success() -> None: assert isinstance(result, PythonInfo) +def test_run_subprocess_skips_child_fd_close_loop(mocker: MockerFixture) -> None: + popen: Final[MockType] = mocker.patch("python_discovery._cached_py_info.Popen", autospec=True, side_effect=Popen) + failure, result = _run_subprocess(PythonInfo, sys.executable, dict(os.environ)) + assert (failure, isinstance(result, PythonInfo), popen.call_args.kwargs["close_fds"]) == (None, True, False) + + def test_run_subprocess_bad_exe() -> None: failure, result = _run_subprocess(PythonInfo, "/nonexistent/python", dict(os.environ)) assert failure is not None