Skip to content

Make psutil optional at runtime#1527

Open
yves-surrel wants to merge 2 commits into
ipython:mainfrom
yves-surrel:make-psutil-optional
Open

Make psutil optional at runtime#1527
yves-surrel wants to merge 2 commits into
ipython:mainfrom
yves-surrel:make-psutil-optional

Conversation

@yves-surrel

@yves-surrel yves-surrel commented Jun 10, 2026

Copy link
Copy Markdown

This PR makes ipykernel's direct use of psutil optional at runtime.

When psutil is installed, existing behavior is preserved. When ipykernel.kernelbase is running with psutil unavailable:

  • usage_request still sends a valid usage_reply with hostname, pid, and cpu_count
  • psutil-dependent CPU and memory telemetry is omitted rather than fabricated
  • child-process enumeration returns an empty list
  • child-process signalling and progressive termination degrade safely

psutil is moved from required runtime dependencies to the test extra so existing subprocess-shutdown coverage remains active in the test environment.

This is intended for constrained platforms where psutil may be unavailable or difficult to build. Runtime optionality is preferable to platform markers here because some constrained builds, such as Python-for-Android, may report sys.platform == "linux" while psutil is unavailable.

Validation:

  • python -m pytest tests/test_kernel_direct.py -q
  • python -m pytest tests/test_kernel.py -q

Addresses #1523

The remaining PyPy failures appear unrelated to this PR.

This PR only changes ipykernel's direct psutil usage in kernelbase.py, plus the corresponding dependency/test updates. It does not modify the subshell execution path, threading code, Windows-specific code, or CI workflow configuration.

One failure is in tests/test_subshells.py::test_run_concurrently_sequence[...], and another appears to be a Windows+PyPy timeout while waiting on a threading condition variable. I do not see a direct connection to the changed usage_request fallback or child-process cleanup fallback paths.

I will leave these unchanged unless maintainers think they reproduce specifically because of this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant