Unable to quit infinite while loop in idle 3.12.0 (64 bit) with keyboard interrupt

I am learning python, in IDLE when i write

# infinite while loop
i = 1
while i < 2:

it produces an infinite while loop . But for some reason I am unable to use the keyboard interrupt (ctrl + C) Idle crashes and have to close it in windows

I am using windows 10.

I think this is expected in IDLE – not the crash perhaps, but the impossibility or near-impossibility of breaking out of a tight infinite loop when this is run in IDLE. If you just run the command-line Python REPL (started by running python or python3 without arguments), you will be able to break out “immediately” of such a tight loop by hitting Ctrl+C, but when running IDLE, it seems to be practically impossible. If there is a little delay inside the loop (for instance by adding time.sleep(.1) then IDLE is also able to break out, but without delay or with a sleep smaller than 0.01 sec it’s difficult/impossible and the only way to end then is to kill the whole process. This behavior is not platform dependent – same thing happens on other OS’s too. I don’t know why the IDLE REPL behaves differently from the simple command-line REPL, but I guess this is somehow caused by the extra TkInter layer that controls the IDLE GUI.

I’d be curious to read a real explanation to replace my hand-waving one – someone who knows the Python idlelib should be able to give one.

1 Like

The minimal interactive reproducer is while 1: 1 (or print(1) in batch mode). I opened issue 112938 to see if there is any way to stop IDLE from being write-locked, or doc the issue if not. On Mac, nothing gets printed before freezing.


@tjreedy - Thanks for filing the issue. I love the minimal reproducer while 1: 1 :rofl:

Pedantically, a space isn’t needed after the colon :wink:

1 Like