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:

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.

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 workspace root (project 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.

Topics:

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:

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.

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 workspace root (project 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.