Debugging
Pages 46
- Home
- Autocomplete Intellisense
- Capture User Input via input() or raw_input()
- Contribution
- Debug Library Functions
- Debugging
- Debugging : Sudo (root privileges)
- Debugging Django
- Debugging nosetests
- Debugging over SSH
- Debugging py.test
- Debugging: Flask
- Debugging: Google App Engine
- Debugging: Remote Debuging
- Documentation
- Documentation: Python for Visual Studio Code
- Formatting
- Jupyter (IPython)
- Jupyter (IPython) Prerequisites
- Jupyter Configuration
- Jupyter Examples
- Jupyter: Getting Started
- Linting
- Miscellaneous
- nose Framework
- PySpark
- pytest Framework
- Python Path and Version
- Q&A
- Refactoring
- Refactoring: Extract Method
- Refactoring: Extract Variable
- Refactoring: Rename
- Refactoring: Sort Imports
- Terminal Console Apps
- TODO:
- Troubleshooting
- Troubleshooting Debugger
- Troubleshooting Formatting
- Troubleshooting Intellisense Autocompletion
- Troubleshooting Jupyter
- Troubleshooting Linting
- Troubleshooting Virtual Environments
- unitest (Standard Unit testing) Framework
- Unitest: More Options
- UnitTests
- Show 31 more pages…
Clone this wiki locally
Debugging
The extension supports debugging of a number of types of python applications.
However these are in active development.
The following debugging capabilities are supported:
- Watch window
- Evaluating expressions
- Locals
- Arguments
- Expanding children
- Break points
- Conditional break points
- Pausing (breaking into) running programs
- Custom startup directory
- Debugging Django applications
- Debugging Google App Engine
- Terminal/Console Apps
- Remote Debugging
- Debugging nosetests
- Debugging pytest
Debugging Options/Configuration
Debugging a standard python application is possible by adding the standard configuration settings in the launch.json file as follows:
{
"name": "Python",
"type": "python",
"pythonPath":"${config.python.pythonPath}",
"request": "launch",
"stopOnEntry": true,
"console": "none",
"program": "${file}",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"env": {"name":"value"}
}program
This setting points to the fully aualified path of the python program to be debugged.
The recommended value for this setting is ${file}.
Resulting in the debugging of the active file in the editor.
Entering the name of the Python file is also supported. However you need to ensure the file name is fully qualitified path. You have two options:
- Option 1: Provide the fully qualified path as follows
{
"name": "Python",
"program": "/Users/xxx/Projects/PokemonGo-Bot/pokemongo_bot/event_handlers/__init__.py",
"cwd": "${workspaceRoot}",-
Option 2: Provide the fully qualified path as follows
Assuming your workspace root is
/Users/xxx/Projects/PokemonGo-Bot
{
"name": "Python",
"program": "${workspaceRoot}/pokemongo_bot/event_handlers/__init__.py",
"cwd": "${workspaceRoot}",pythonPath
This setting points to the python interpreter to be used for debugging purposes.
The default value of this setting is "${config.python.pythonPath}", resulting in the use of the python interpreter configured in settings.json.
args
Initialize this setting with the arguments to be passed to the python program.
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"args": [
],
"program": "file",
"cwd": "workspaceRoot",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},stopOnEntry
The setting "stopOnEntry":true will cause the debugger to break at the first line of the python program being debugged.
If this is not desired, then change the value from true to false.
The default value of this setting is true.
console
This setting controls the display of a terminal (console window) for debugging. By default this is turned off (with a value of "none").
If a terminal (console window) is to be displayed whilst debugging, then use one of the following settings:
-
"console": "integratedTerminal": The integrated terminal will be used -
"console": "externalTerminal": An external terminal will be used
For further details on debugging terminal (console) apps, go here.
cwd
This directory can be used to control (specify) the current directory of the python program being debugged.
This defaults to the directory containing the file being debugged.
Set the value to "${workspaceRoot}" if required to use the workspace root (project directory) as the current directory.
debugOptions
The setting "RedirectOutput", will cause the debugger to print all output from the program into the VSCode debugger output window.
If this setting is missing, then all output from the program (such as those generated by Print commands) will not be displayed in the debugger output window.
If the setting externalConsole is enabled, then the suggestion would be to remove the setting "RedirectOutput" from this list.
This is because the output from the program will be displayed on the console window, and there's no need for this information to be duplicated on the debugger output window.
env
The setting "env", can be used to set custom environment variables for the debugger process.
If this setting is missing, then no additional environment variables are set. Whether this is set or not, the debugger process will inherit the environment variables.