^C
次のプログラムで竜巻をブロックしているときに押すioloop.start()
と、Python はすぐに終了し、KeyboardInterrupt (またはその他の例外) は発生しません。何が起こっていて、どうすればキャッチでき^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、
- Python 2.7.6 (デフォルト、2013 年 11 月 10 日 19:24:18) [MSC v.1500 32 ビット (Intel)] on win32
- 竜巻==3.2