【问题标题】:Python: Tornado ioloop killed with no exceptions on KeyboardInterruptPython:Tornado ioloop 在 KeyboardInterrupt 上没有异常被杀死
【发布时间】:2014-02-16 22:46:39
【问题描述】:

当我在下面的程序中阻止龙卷风的ioloop.start() 时按^C 时,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 位(英特尔)] 在 win32 上
  • 龙卷风==3.2

【问题讨论】:

    标签: python windows tornado keyboardinterrupt


    【解决方案1】:

    我确定这个问题是因为我在 Windows 上使用 Git Bash 控制台。当我使用常规命令提示符时,一切都按预期工作。我怀疑 Git Bash 正在捕获 ^C 并终止进程。

    【讨论】:

      【解决方案2】:

      Windows 有不同的控制台信号

      试试 Ctrl + 中断 或者 Ctrl + D

      【讨论】:

        猜你喜欢
        • 2019-05-01
        • 2016-02-03
        • 1970-01-01
        • 1970-01-01
        • 2016-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多