Repository navigation
Skip lazily imported traceback formatter modules in debugger attach rules - #1600
Open
Dikshant-Neupane wants to merge 1 commit into
Open
Dikshant-Neupane wants to merge 1 commit into
Dikshant-Neupane wants to merge 1 commit into
Conversation
This branch has not been deployed
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 free
to 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.
Fixes #1596
With the
raisedexception filter on, the debugger stopped 245 times when user code raised (1 in the user cell, 244 inside the traceback formatting stack: pygments, stack_data, executing, asttokens). Since IPython 9.17, IPython imports those modules lazily when formatting a traceback, so they are not loaded when the kernel starts and their files are not inkernel_modules.This adds
{\"module\": ..., \"include\": False}rules for the five lazily imported modules inDebugger.attach, which is the mechanism debugpy actually honors.Why module rules instead of
__tracebackhide__(as suggested in the issue): that flag is honored only by IPython's own traceback display and pdb-based debuggers, not by debugpy/pydevd. A grep of the vendored pydevd 1.8.22 finds zero references to it, so setting the flag cannot suppress these stops. The eager-import alternative was measured at about 390 ms on every kernel start and rejected.Trade-off:
raisedno longer stops inside pygments itself when user code calls pygments directly. That matches how every library loaded at kernel start is already treated by the path rules.Verification: the issue's repro script verbatim gave 245 stops before the fix and 1 stop after, in the user cell only; runtime dropped from about 61 s to about 5 s. New test
test_no_stop_in_traceback_formatter_on_raised_exceptionfails without the fix (assert 245 == 1) and passes with it. Full debugger suite 16 passed;ruff checkandruff formatclean; mypy with the repo config clean. A separate check with a user library that raises and catches aValueErrorinternally still stops exactly once inside that library, so there is no over-suppression.