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:
As you can see in the image it launches a new terminal rather than using the existing terminal.
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:
This would be a great feature, but, unfortunately, we're constrained by VSCode itself here. The debugger can only request to run something in a terminal with a given title (and you can specify that title in launch.json by setting "consoleTitle", if you don't like the default "Python Debug Console"). However, whether and how to reuse an existing terminal is entirely down to VSCode. I was hoping that it'd reuse an existing terminal with matching title - but this doesn't seem to be the case.
microsoft/vscode#68123 might be relevant here, although it's not quite the same, since it's about grouping newly spawned terminals.
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).