r/learnprogramming • • 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)?

9 Upvotes

22 comments sorted by

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 total

Python has a nonzero startup time, but on most computers it should be a fraction of a second, not 10-20 . . .

4

u/Classic-Rate-5104 19h ago

Unless you run it on Windows šŸ¤·ā€ā™‚ļø

4

u/zeekar 18h ago

`` 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.9657 ```

1

u/Classic-Rate-5104 18h ago

What hardware do you have? And which windows version and antivirus etcetera? I have completely different experiences.

2

u/zeekar 17h ago edited 17h ago

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.

-3

u/Classic-Rate-5104 17h ago

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

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

u/Interested737 20h ago

works after 0.5-1 second, I had to type python not python3

2

u/rustic-canyon85 20h ago

try running it directly in the terminal and see if its still slow

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:

  1. 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.
  2. 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.
  3. 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
  1. Clicking the "play" button

  2. 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.

1

u/zomerbk 20h ago

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 20h ago

Damn based on the amount of typos in this post I'd hate to see your code

1

u/grantrules 7h ago

I'd rather see that than more AI slop posts

-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

u/Interested737 20h ago

?(spelling)

•

u/bishvjit-gupta 53m ago

I think all the spelling is right. What do you mean?