Home > Net >  Python programs slow to start in VS Code terminal
Python programs slow to start in VS Code terminal

Time:11-03

When I run any program in the VS Code terminal, the program takes about 20-30 seconds before it starts running. After it starts, it runs at relatively normal speeds.

This is new behavior: code I was running last school year had much faster startup times. I am using no new extensions I am aware of that would be slowing this down- I have tried disabling extensions I don't need, but to no avail. None of the listed startup times appear to be the problem (Python extension's time is 282 ms, and that's the longest listed startup time).

I've tried uninstalling and reinstalling VS Code, and also tried installing Python 3.10.0 (I am using 3.9.0 by default).

Here is a sample of code that shouldn't take much time to start up, but does:

var = 1
while True:
    print(var)
    var  = 1

This slow-start behavior is the same across all Python programs I've been running, infinite loop or no.

VS Code info:
Version: 1.61.2 (user setup)
Commit: 6cba118ac49a1b88332f312a8f67186f7f3c1643
Date: 2021-10-19T14:57:20.575Z
Electron: 13.5.1
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

FYI, I am a programming teacher, with no educational background in programming. I promise I'll do my best to answer your questions, but I may need some handholding to get there. Thank you for any help.

Edit: I've been in the habit of killing the terminal when I make changes to a program, then saving my program, then running it. I kill the terminal a lot. It turns out that if I only save and rerun my program (without killing the terminal), the first run starts slow, but then subsequent runs start just fine. This leads me to believe that the problem isn't with the program itself, but with my terminal starting slowly.

CodePudding user response:

Going from your comments, I'm pretty sure the problem is not python or VS Code in your system, but PowerShell taking a much longer time to start.

I would advise you to switch to CMD, which takes much less time to start. Go to setting.json and add the line

"terminal.integrated.defaultProfile.windows": "Command Prompt"

Alternatively, you can click the button in the integrated terminal, select Default Profile and select Command Prompt when the prompt appears on the top of the screen, as shown in the documentation of VS Code

If you want to fix PowerShell being slow itself, there are a lot of answers available online. You seem to be using an older version of PowerShell. You can update it to PowerShell Core 6, but I don't think it would be necessary. Changing the default profile to CMD should be enough to solve your issue.

  • Related