Skip to content

Skip lazily imported traceback formatter modules in debugger attach rules - #1600

Open
Dikshant-Neupane wants to merge 1 commit into
ipython:mainfrom
Dikshant-Neupane:fix/1596-pygments-tracebackhide
Open

Dikshant-Neupane wants to merge 1 commit into
ipython:mainfrom
Dikshant-Neupane:fix/1596-pygments-tracebackhide

Conversation

@Dikshant-Neupane

Copy link
Copy Markdown

Fixes #1596

With the raised exception 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 in kernel_modules.

This adds {\"module\": ..., \"include\": False} rules for the five lazily imported modules in Debugger.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: raised no 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_exception fails without the fix (assert 245 == 1) and passes with it. Full debugger suite 16 passed; ruff check and ruff format clean; mypy with the repo config clean. A separate check with a user library that raises and catches a ValueError internally still stops exactly once inside that library, so there is no over-suppression.

This branch has not been deployed

No deployments
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.

Pausing on raised exceptions also stops inside pygments since IPython 9.17

1 participant