VS Code opens a new debug console every time I build/run

Viewed 7716

Every time I build or run a program in VSCode a new python debug console is loaded. Before I know it I have 20+ and need to start deleting them. After 32 open consoles I get the error "The terminal process terminated with exit code: 256". I changed the terminal from the default console to git bash recently. How can I stop this?

enter image description here

5 Answers

A way around this issue is to stop VS Code from redundantly printing to the TERMINAL during debugging in the first place. Since it prints to the DEBUG CONSOLE as well, you can use that instead.

Change console to "none" "internalConsole" in each configuration in your project's launch.json file:

"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "internalConsole"
    }
]

May 2019 Update: the "none" option was replaced by "internalConsole" so I edited my answer to reflect that. Here's the relevant GitHub Issue.

Adding "args": ["&&", "exit"], to launch.json remedies this for Git Bash. Certainly a hack, but I no longer have to manually close many debug terminals.

This may have been resolved in recent debug updates to core VS Code within the last year (as of 8/2022), but I was still seeing this intermittently.

I don't know if this will help the original poster, but I discovered that for me the issue persisted due to using Git Bash as the default terminal in Windows. Switching to Command Prompt as the default terminal fixed the issue. I haven't tested with other platforms or terminals.

Changing the default terminal to Command Prompt causes the Python extension to launch the "Python Debug" terminal with Command Prompt instead of Git Bash. I did log a VS Code/Python Extension defect about this. The initial response is that Git Bash is not officially supported currently.

There appears to be a communication problem between the Git Bash terminals and VS Code that causes this issue. Some of the characters between Git Bash and VS Code get dropped. Sometimes this mangles the debug command and I get and error and have to retry in addition to getting an extra debug window.

There is some additional background info and hacks to fix this from the past in this answer.

Actually you can delete all the instances of the terminal just by clicking on the trash can icon . If it does not work for the first time, restart the VS Code and try again.

Related