在龙卷风中,如何查看在PeriodicCallback调用的协程中引发的异常?

我编写了一个程序,该程序具有一个从主程序定期调用的协程,ioloop如下所示:


from tornado import ioloop, web, gen, log

tornado.log.enable_pretty_printing()

import logging; logging.basicConfig()


@gen.coroutine

def callback():

    print 'get ready for an error...'

    raise Exception()

    result = yield gen.Task(my_async_func)


l = ioloop.IOLoop.instance()

cb = ioloop.PeriodicCallback(callback, 1000, io_loop=l)

cb.start

l.start()

我得到的输出很简单:


$ python2 app.py

get ready for an error...

get ready for an error...

get ready for an error...

get ready for an error...

将raise Exception()被自动忽略!如果我将回调更改为


def callback():

    print 'get ready for an error...'

    raise Exception()

我得到了我期望(和需要)的完整堆栈跟踪。使用协程时如何获取堆栈跟踪?


摇曳的蔷薇
浏览 289回答 2
2回答

慕妹3242003

我不完全清楚为什么,但是更改@gen.coroutine为@gen.engine允许异常正确冒泡。它仍然仍然异步工作。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python