Uh oh!
There was an error while loading. Please reload this page.
Defer debugpy and psutil imports until they are actually needed - #1543
Open
Carreau wants to merge 1 commit into
Open
Defer debugpy and psutil imports until they are actually needed#1543Carreau wants to merge 1 commit into
Carreau wants to merge 1 commit into
Conversation
Both imports were paid for on every kernel startup even though most sessions never debug or ask for usage information. * `IPythonKernel.debugger` is now a lazily-created property; the debugger (and the debugpy import) is only built on the first debug request. `poll_stopped_queue` is scheduled at that point rather than in `start()`. * `debugger_class` was a `Type` trait, which traitlets resolves — and therefore imports — as soon as the kernel is instantiated. It is replaced by a plain `debugger_class_name` string; `debugger_class` remains as a deprecated property, and subclasses still overriding it keep working with a DeprecationWarning. * `psutil` is imported through `_get_psutil()`, which caches the (possibly None) result on first use. On a local test (where I have optimisation in IPython and traitlets as well), this brings the startup time from 220ms to 170ms
Carreauforce-pushed
the
lazy-debug-and-psutil
branch
from
August 4, 2026 16:44
722618c to
ac6ca05CompareCarreau
marked this pull request as ready for review
August 5, 2026 07:39
Carreau
commented
Aug 5, 2026
MemberAuthor
CI failure will be taken care of by #1544 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both imports were paid for on every kernel startup even though most sessions never debug or ask for usage information.
IPythonKernel.debuggeris now a lazily-created property; the debugger (and the debugpy import) is only built on the first debug request.poll_stopped_queueis scheduled at that point rather than instart().debugger_classwas aTypetrait, which traitlets resolves — and therefore imports — as soon as the kernel is instantiated. It is replaced by a plaindebugger_class_namestring;debugger_classremains as a deprecated property, and subclasses still overriding it keep working with a DeprecationWarning.psutilis imported through_get_psutil(), which caches the (possibly None) result on first use.On a local test (where I have optimisation in IPython and traitlets as well), this brings the startup time from 220ms to 170ms