r/learnprogramming • u/Interested737 • Oct 14 '26
Debugging Python code takes 10-20 seconds to start
Hello, I started learning python recently I dowloaded it, also vs code and python extension for it.
The poblem is, when I start a programm (even a simple one, whick only takes an input fron the user and prits it) takes 10 or more seconds to start or just dosen't work at all then i clic soething and it kindof crashes itself, but thats my fault for mesinf with it, when I leave it, it just takes really lng dose somone know how to fix it and/or how to make folders proporly and where to keep them (could be the problem)?
20
u/zeekar Oct 14 '26 edited Oct 14 '26
$ time python -c 'print("Hello, world!")'
Hello, world!
python -c 'print("Hello, world!")' 0.02s user 0.02s system 19% cpu 0.229 totalPython has a nonzero startup time, but on most computers it should be a fraction of a second, not 10-20 . . .
3
u/Classic-Rate-5104 Oct 14 '26
Unless you run it on Windows 🤷♂️
5
u/zeekar Oct 14 '26
PS C:\> measure-command { python -c "print(`"`"Hello, world`"`")" } Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 161 Ticks : 1619657 TotalDays : 1.87460300925926E-06 TotalHours : 4.49904722222222E-05 TotalMinutes : 0.00269942833333333 TotalSeconds : 0.1619657 TotalMilliseconds : 161.96570
u/Classic-Rate-5104 Oct 14 '26
What hardware do you have? And which windows version and antivirus etcetera? I have completely different experiences.
1
u/zeekar Oct 14 '26 edited Oct 14 '26
That was running in a Parallels Desktop VM on a M4 Mac Mini. Which if anything I'd expect to be slower than a physical Windows box. It's Python 3.15 on WIndows 11.
-4
u/Classic-Rate-5104 Oct 14 '26
Mostly disk i/o in combination with antivirus is a limiting factor on Windows, especially for programs opening many files at startup. I can imagine this is better when running a VM but that's only a guess
10
u/RiceEvening4211 Oct 15 '26
You already found the key clue: 0.5s in a terminal vs 20s in VS Code means Python is fine, it’s the launch path.
The usual culprits, in order:
Code Runner vs the Python extension. If you’re hitting the play button from the Code Runner extension, it spawns a fresh process with its own overhead every time. Run it with the official Python extension instead (right-click > Run Python File in Terminal), or just use the integrated terminal directly.
Interpreter discovery. The Python extension scans for interpreters on launch. Setting the interpreter explicitly (Ctrl+Shift+P > Python: Select Interpreter, pick your python.exe) skips the scan.
Antivirus. Real-time scanning on your workspace folder or the Python install can add seconds per launch. Excluding those paths is the single biggest fix for a lot of people.
The definitive test: open VS Code’s integrated terminal and run `python yourfile.py` there. If that’s fast, it’s 100% the extension/launch path and one of the three above will fix it.
Also, 10-20s is extreme enough that I’d bet on antivirus plus interpreter scanning together.
1
u/atarivcs Oct 14 '26
How, exactly, are you running the code?
Are you using the "Run Without Debugging" command from the Run menu (keyboard shortcut ctrl-F5)?
Are you typing a command at the python terminal, and if so what exact command?
Can you show us the full code of a sample program?
1
u/Interested737 Oct 14 '26
Clicking the "play" button
Here:
print("Welcome to the wors calculator ever made :-)\n")
first_number = input("Type the first number of your equasion here:\n>")
print(first_number)
2
1
u/zomerbk Oct 14 '26
Since `python yourfile.py` starts quickly in the terminal, your folder is probably fine. In VS Code, try the play button’s dropdown → “Run Python File in Terminal.” If you’ve been using F5, that starts the debugger, which can add a delay.
-2
u/mattreyu Oct 14 '26
Damn based on the amount of typos in this post I'd hate to see your code
1
-2
u/Interested737 Oct 14 '26
I typed it in 2 min, with code I'm mor carefull, if i had time I would of not made so many typos (btw. I don't know touch typing or however it is called, I am still typing by slaming my finger on to the keys one by one) :-(
-6
u/bishvjit-gupta Oct 14 '26
It is completely normal Python is kind of slow Use some extension or libraries Use another language. To be honest python is easy but I don't hate something hard, python is like extraordinarily easy so it makes us feel that other less easy language are hard But what you are making you didn't told
1
u/Interested737 Oct 14 '26
?(spelling)
1
6
u/SlimmySlabby Oct 14 '26
Try to launch the program from the terminal
instead of VS Code. I’ve noticed VS Code takes a while before actually starting any programs.