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