0

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.

1
  • 3
    Please, specify WHERE it doesn't work and how do you use it - otherwise we are unable to help you, we aren't clairvoyants... :) Commented Sep 1, 2009 at 8:27

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.