microsoft / debugpy

An implementation of the Debug Adapter Protocol for Python
https://pypi.org/project/debugpy/
Other
1.85k stars 137 forks source link

VS Code ignores breakpoints in the `importlib` module #1676

Closed Andrej730 closed 2 weeks ago

Andrej730 commented 4 months ago

How to reproduce: 1) Disable justmycode for debugpy (in my case it's disabled both in user and workspace settings). image

2) Create an empty python file.

3) Open Python\Lib\importlib\__init__.py and insert a breakpoint. You can add some print statement to get sense when we're past the breakpoint.

image

4) Start debug for an empty python file with the "Python Debugger: Debug Python file". image

5) Script will be executed but breakpoint is never triggered - though there will be print messages we added on step 3.

As a workaround it's possible to debug it with the classic breakpoint() though it's not as convenient.

paulacamargo25 commented 3 months ago

We do not handle breakpoint in the extension, I am not sure if this a vscode error or debugpy, sending it to debugpy.

judej commented 2 weeks ago

@Andrej730, the issue is due to the way python optimizes the loading of the standard modules. The breakpoint() function or debugpy.breakpoint() are often the most reliable methods for debugging such scenarios.

You could also try attaching to the process and stepping into imporlib code,

Hope that helps.

rchiodo commented 2 weeks ago

I believe this is a special case. Debugpy uses importlib itself. We can't debug modules that are already loaded into the debugger by the debugger. Sticking a breakpoint() in the code doesn't work for me either. It just hangs launching the debugger (well because it's using importlib).