Search code examples
pythonvisual-studio-codepydevvscode-debugger

Run code whenever a breakpoint is hit in VSCode/Python


Is it possible to execute some code whenever a breakpoint is hit in VS Code (PyDev)?

(specifically, I'd like to print some state whenever I hit a break point, rather than have to type that command manually all the time)


Solution

  • In the debug bar is a Watch View. Here you can define expressions that are evaluated when the debugger returns control to the user (breakpoint or step).

    From your comments I learned that you can enter expressions with side effects like print statements. This is similar to log statements only that they print the stuff when the debugger stops.