When I try to debug a Python file in VS Code, the debugger opens in a new terminal instead of using the existing integrated terminal.
I have tried the following:
Making sure that I have saved my launch.json configuration file.
Restarting VS Code.
Trying debugging a different Python file.
If I am using a virtual environment, making sure that the virtual environment is activated.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
Environment:
- VS code Version: 1.79.2 (user setup)
- OS: WSL Ubuntu
As you can see in the image it launches a new terminal rather than using the existing terminal.
2
Answers
From googling "
github vscode python issues debug reuse terminal
", I found this issue ticket: Run Python Debug Console in Existing Terminal #13040, where a maintainer of the VS Code Python extension, @int19h stated this:Note for historical purposes, there was also an older bug where debugging with a Python-type launch config would cause a new terminal to be created every time instead of reusing an existing debug terminal, but that one seems to have been fixed (see also Debug mode spawns a new "Python Debug Console" every time with console set to integratedTerminal #132 and In VSCode, Python debugger launches a new Terminal every time I debug).
This is normal behavior, if you don’t have a debug terminal, it will create a new terminal for debugging, after that all debugging will use this terminal instead of creating a new one, even if you debug another script. Unless you close this debugging terminal, it will create a new one next time you debug.