當我按下^C
在下面的程序中阻塞龍捲風的ioloop.start()
時,Python立即退出並且沒有發生KeyboardInterrupt(或任何其他異常)。發生了什麼,我該如何捕獲^C
?Python:Tornado ioloop在KeyboardInterrupt上沒有任何例外被殺死
import tornado.ioloop
import tornado.web
ioloop = tornado.ioloop.IOLoop.instance()
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
# has no effect
# tornado.ioloop.PeriodicCallback(lambda:None, 1000).start()
print 'starting'
try:
ioloop.start()
except KeyboardInterrupt:
print '^C pressed'
finally:
print 'done'
輸出:
$ /c/Python27x32/python test.py
starting
$
預期輸出:
$ /c/Python27x32/python test.py
starting
^C pressed
done
$
我運行:
- 的Windows 8.0的X64,
- 的Python 2.7.6(默認,11月10日2 013,19時24分18秒)[MSC v.1500 32位(英特爾)]在Win32
- 龍捲風== 3.2