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

firebase - How to wait value in Ionic 2 -

Jenkins: find build number for git commit -

typescript - Typings for sub-folders inside a root index.d.ts -