Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code - Python debugging - Step into the code of external functions when executing

In a Python project, how do you tell the built-in VSCode debugger to step into the code of functions from other libraries on execution?

I know it is possible for functions implemented in standard libraries by adding a

"debugOptions": ["DebugStdLib"] 

to your configuration in launch.json as specified here, however it does not seem to be possible to force the debugger to step into the code of non-standard modules, such as the ones you have written yourself and imported into the current file.

like image 987
John Smith Avatar asked Dec 03 '18 13:12

John Smith


People also ask

How do I debug a Python function in VS Code?

Start by clicking on the debug icon on the left-hand panel of your VSCode. Click on create a launch. json file, which will give you a drop-down of all your currently installed debuggers. By default, a Python debugger is not installed in VSCode.

How do you debug a program in Python Is it possible to step through the Python code?

To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().


2 Answers

In order to improve the accepted answer by John Smith, it is worth mentioning that now the option has been renamed again. The new option is

"justMyCode": false 

and as per the documentation

When omitted or set to True (the default), restricts debugging to user-written code only. Set to False to also enable debugging of standard library functions.

like image 170
maephisto Avatar answered Sep 28 '22 04:09

maephisto


This is done by customising your debugger.

If you haven't already, you need to initialise the debugger customisation. You can do this by opening the debugger section in the side bar and selecting create a launch.json file.

Once this is done, a launch.json file will be created in a .vscode folder in your workspace.

Edit this file. It will look something like this:

{     ...,     "configurations": [         {             "name": "Python: Current File",             "type": "python",             "request": "launch",             "program": "${file}",             "console": "integratedTerminal"         }     ] } 

Add "justMyCode": false to the "Python: Current File" configuration, like this:

{     ...,     "configurations": [         {             "name": "Python: Current File",             "type": "python",             "request": "launch",             "program": "${file}",             "console": "integratedTerminal",             "justMyCode": false         }     ] } 

True as of Visual Studio Code version 1.59.0.

Reference: https://code.visualstudio.com/docs/python/debugging

like image 30
Denziloe Avatar answered Sep 28 '22 04:09

Denziloe