There is a lot of confusion around Visual Studio Code tasks and the debugger. Let's discuss about it first so that we understand when to use tasks and when to use the debugger.
Tasks
The official documentation says -
Lots of tools exist to automate tasks like linting, building,
packaging, testing, or deploying software systems. Examples include
the TypeScript Compiler, linters like ESLint and TSLint as well as
build systems like Make, Ant, Gulp, Jake, Rake, and MSBuild.
.... Tasks in VS Code can be configured to run scripts and start
processes so that many of these existing tools can be used from within
VS Code without having to enter a command line or write new code.
So, tasks are not for debugging, compiling or executing our programs.
Debugger
If we check the debugger documentation, we will find there is something called run mode. It says -
In addition to debugging a program, VS Code supports running the
program. The Debug: Start Without Debugging action is triggered with
Ctrl+F5
and uses the currently selected launch configuration. Many of
the launch configuration attributes are supported in 'Run' mode. VS
Code maintains a debug session while the program is running, and
pressing the Stop button terminates the program.
So, press F5 and Visual Studio Code will try to debug your currently active file.
Press Ctrl + F5 and Visual Studio Code will ignore your breakpoints and run the code.
Configuring the debugger
To configure the debugger, go through the documentation. In summary it says, you should modify the launch.json
file. For starters, to run the code in integrated terminal (inside Visual Studio Code), use -
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
To run the code in an external terminal (outside of Visual Studio Code), use -
{
"name": "Python: Current File (External Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "externalTerminal"
}
N.B. If all documentation was easy to search and understand then we probably would not need Stack Overflow. Fortunately, the documentation I mentioned in this post is really easy to understand. Please feel free to read, ponder and enjoy.