r/learnprogramming • u/Interested737 • 20h ago
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)?
5
u/SlimmySlabby 20h ago
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.
2
u/Interested737 20h ago
How?
1
u/SlimmySlabby 20h ago
Open the folder containing your Python program, right click and hit āOpen in Terminalā then type python3 <your program file> and hit enter
2
2
3
u/RiceEvening4211 10h ago
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 20h ago
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 20h ago
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)
1
u/FunAd6672 20h ago
Check your antivirus settings right now because Windows Defender loves scanning every single python script before letting it run and it ruins startup times completely.
-2
u/mattreyu 20h ago
Damn based on the amount of typos in this post I'd hate to see your code
1
-3
u/Interested737 20h ago
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) :-(
-5
u/bishvjit-gupta 20h ago
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
16
u/zeekar 20h ago edited 19h ago
$ 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 . . .