views:

328

answers:

1

How to generate a KeyboardInterrupt in Windows?

while True:
    try:
        print 'running'
    except KeyboardInterrupt:
        break

I expected CTRL+C to stop this program but it doesn't work.

+2  A: 

Your code is working ok when ran into a windows console.

Ctrl+C generating a KeyboardInterrupt is a console feature. If you run it from a text editor like SciTE, it will not work.

luc
That's right, it works fine when run from Vim (who starts a console) both on Linux and Windows. Thanks for the tip.
dugres