python except and finally do not work with KeyboardInterrupt -




after executing following code, when press control+c, execution ends , nothing printed console

import time  x = 1  try:     while true:     print x     time.sleep(.3)     x += 1  except keyboardinterrupt:     print "bye"   finally:     print "this one" 

there indentation problem in code. if changed to:

import time  x = 1  try:     while true:         print x         time.sleep(.3)         x += 1  except keyboardinterrupt:     print "bye"   finally:     print "this one" 

output is:

1 2 3 4 5 6 bye 1 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -