0

I apologize in advance as this is going to be a vague question. I just hope someone has the same experience and can help me. Imagine a simple script that has this simple code in it:

for i in range(100):
    print(i)

When I run the script from the terminal (CMD), occasionally, the loop gets stuck but as soon as I press the Enter key in the terminal, it jumps back into working and the loop continues. I want to emphasize that there is nothing like a user input line in the code causing a pause in the loop until a key is pressed or anything like that in the code. Also, this never happens if I run the code inside an IDE. This only happens in CMD and in possibly in any script that has a loop like this.

Saeed
  • 1,848
  • 1
  • 18
  • 26

1 Answers1

0

When you click on the command prompt it goes into select mode, you will see a white square. You will also see at the top of the command prompt it will say select. This will pause anything running in the cmd.

Select Mode

If you press enter that will get it out of select mode and will continue running the program

Non select mode

I believe this is what your running into.

SomeSimpleton
  • 350
  • 1
  • 2
  • 12
  • Holy molly, I had no clue about this but I tested it and you are 100% right. Is there any way to disable that so that I accidentally do not pause my code like that? – Saeed Aug 09 '23 at 03:40
  • 1
    Yep, found it here https://stackoverflow.com/questions/33883530/why-is-my-command-prompt-freezing-on-windows-10/76855923#76855923 – Saeed Aug 09 '23 at 03:56
  • 1
    @Saeed that is correct and I believe it only pauses anything that is writing out to stdout/stderr in the terminal. If I am not mistaken the program will continue running until it has to write to stdout/stderr and then halt there until you leave select mode. – SomeSimpleton Aug 09 '23 at 17:01