当扭曲反应器正在运行并且在未捕获的延迟中发生异常时,“未处理的错误”将与回溯和异常一起打印到终端。是否可以处理/拦截这些异常(例如,设置回调或覆盖方法)?
编辑:我知道我可以通过将 errback 添加到 deferrerd 来捕获失败。我想知道的是,是否有办法拦截一个未处理的故障/异常,该故障/异常已经沿着链向上到达反应堆。
编辑:本质上,我想知道扭曲反应器是否有全局错误处理程序或可以访问的东西。我想知道,因为它会打印故障的回溯和错误。
例子:
Unhandled Error
Traceback (most recent call last):
File "/var/projects/python/server.py", line 359, in run_server
return server.run()
File "/var/projects/python/server.py", line 881, in run
reactor.run()
File "/usr/local/lib/python2.6/dist-packages/Twisted-11.0.0-py2.6-linux-x86_64.egg/twisted/internet/base.py", line 1162, in run
self.mainLoop()
File "/usr/local/lib/python2.6/dist-packages/Twisted-11.0.0-py2.6-linux-x86_64.egg/twisted/internet/base.py", line 1171, in mainLoop
self.runUntilCurrent()
--- <exception caught here> ---
File "/usr/local/lib/python2.6/dist-packages/Twisted-11.0.0-py2.6-linux-x86_64.egg/twisted/internet/base.py", line 793, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/var/projects/python/server.py", line 524, in monitor
elapsed = time.time() - info.last
exceptions.NameError: global name 'info' is not defined