Python:Tornado ioloop在键盘中断上无异常死亡
当我在下面的程序中阻塞tornado的Python:Tornado ioloop在键盘中断上无异常死亡,python,windows,tornado,keyboardinterrupt,Python,Windows,Tornado,Keyboardinterrupt,当我在下面的程序中阻塞tornado的ioloop.start()时按^C,Python会立即退出,并且不会引发键盘中断(或任何其他异常)。发生了什么事?我如何抓住^C import tornado.ioloop import tornado.web ioloop = tornado.ioloop.IOLoop.instance() class MainHandler(tornado.web.RequestHandler): def get(self): self.wr
ioloop.start()
时按^C
,Python会立即退出,并且不会引发键盘中断(或任何其他异常)。发生了什么事?我如何抓住^C
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
- win32上的Python 2.7.6(默认,2013年11月10日19:24:18)[MSC v.1500 32位(英特尔)]
- 龙卷风==3.2