当我按下^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