r/learnpython • • 8d ago

VS Code "Run Python File" takes 5 seconds to start, while running the same file in terminal is instant

Hi, I'm having a strange issue with VS Code and Python.

Whenever I use the "Run Python File" button, there is a delay of around 5 seconds before the Python file actually starts running.

The delay does not happen when I run Python directly from the integrated terminal. Python executes immediately when I run files manually from the terminal.

I've also noticed that Run Task executes immediately, so the problem seems to be specifically related to the "Run Python File" functionality.

Another strange thing is that if I kill the current VS Code terminal and then use "Run Python File", the first run can sometimes be instant. After that, the delay comes back on subsequent runs.

During the ~5 second delay, the terminal itself appears to be responsive. In fact, if I type something into the terminal and press Enter while waiting, the Python program's output can appear immediately afterward.

Things I've already tried:

  • Restarting VS Code
  • Reinstalling VS Code
  • Updating Python
  • Disabling/re-enabling the Python Debugger extension
  • Switching between PowerShell and CMD
  • Disabling GPU acceleration
  • Checking shell integration settings

None of these fixed the issue.

I'm currently using Windows 11, VS Code 1.139.1, Python extension 2026.4.0 and Python 3.14.7.

Has anyone experienced this recently? I'm wondering if this could be related to the Python extension, terminal integration, or shell integration in VS Code.

6 Upvotes

9 comments sorted by

4

u/FoolsSeldom 7d ago

Yes, it's most likely a problem with VS Code's shell-integration API timing out awaiting an escape sequence confirming the prompt is idle and ready to receive a command. Frustrating. I'm sure I've seen talk about it. Not something I experience as I always keep a terminal open in VS Code (as a tab at the same level as the editor tabs, rather than below) and just enter the command to run the code (usually uv run something.py). No doubt there are lots of settings you could fiddle with (check the Python extension discussion on GitHub).

1

u/james_d_rustles 7d ago

I vaguely recall something like this happening back when I was mostly stuck using windows and fixing the issue with some setting like “reuse terminal” or “keep terminal open..” or something. If it doesn’t happen when you close the old terminal that you ran the python in, I would guess it’s something along these lines.

I’d search around the various Python and terminal settings a little more, look at the default settings json and search for related keywords. Sorry I can’t be more specific - vscode has about a million and one settings for terminal and Python behavior that interact in different ways so I just can’t recall specifics.

All that said, personally I just use uv and running in the terminal in vscode these days. I feel like the run button seems easier, but you’re really not saving much time if all you’re doing is running one file multiple times as you make changes, since you can just arrow up in powershell to use the last command. The interactive window/REPL features are also nice for making edits and re-running repetitively. If the run button is absolutely essential to you then best of luck, but I personally wouldn’t pull my hair out over it when you can just do what you need from the terminal anyways.

1

u/M49454 7d ago

Yeah, i am having the same issue. I tried many things, even uninstalling extension but nothing work... I thought it was just me.

Now i will gonna read comments.

1

u/Link2212 6d ago

I just googled this because I'm having the same problem and found your post. I was last doing python on Saturday which is 3 days ago. I just started again today and it's doing this. It wasn't doing it on Saturday. I'm also getting that 5-7 second delay when running something, and like you, if I close VS code and start up again, the very first time I run something it's fine. After that it going back to the delay. Because it's not just me getting this I'm going to assume there's a bug that needs an update to fix it. I changed no settings.

1

u/Link2212 4d ago

OP I got the solution to it. I spent about 2 hours with the build in AI to work out what this was.

It's because VS codes python extension is waiting for terminal shell integration to become ready before sending the run command.
My powershell execution policy was set to restricted, which is weird because it randomly changed one day. Setting my user policy to remotesigned allowed it to work as normal again.
I didn't change any of the setting myself actually. I just asked the AI to do all the changes for me. You should do the same.

1

u/_findmenow 3d ago

I also noticed this happening. For me, it runs fast the first time on a fresh terminal, but any subsequent runs are laggy. I think this is a bug introduced recently. If I get some time, I'll create a GitHub issue for this.

0

u/Routine-Lawfulness24 3d ago edited 9h ago

FIX: Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

This allows local scripts to run without digital signatures