Breaking out of a while loop with a key press?

Bengt Richter bokr at
Tue Apr 1 12:49:43 CEST 2003

On Tue, 1 Apr 2003 07:59:44 +0100, "Richard" <richardd at> wrote:

>Hi guys,
>Thank you all for your suggestions. I'm sorry my question was a bit
>ambiguous with regard to the 'console window' reference. I was in fact
>referring to a Win2K Command Prompt (cmd.exe).
>I will try catching the KeyboardInterrupt exception and check that I have no
>bare 'except's anywhere that could be catching this for me.
Note that catching the exception means allowing the exception to interrupt
wherever in your loop execution may be, so you can not expect such a loop exit
to give you a final complete loop execution. See suggestions (mine and
others) for using signal handlers to accomplish orderly loop termination
based on modifying a while loop condition from a signal handler (which
returns to continue execution of the loop where interrupted).

Bengt Richter

More information about the Python-list mailing list