Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions docs/changelog/+probe-close-fds.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The interpreter probe no longer hangs on macOS when the forked child blocks closing an inherited file descriptor
before exec.
2 changes: 2 additions & 0 deletions src/python_discovery/_cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/python_discovery/test_cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down