python2中的rxpy获取异常的堆栈跟踪

2024-06-09 14:29:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python2.7中使用rxpy

在处理通过可观察流漏斗状传输的异常时,是否有任何方法可以获得stacktrace

例如,考虑这个例子:

from __future__ import print_function
from rx import Observable

def test(x):
  raise ValueError("error!")

# will print "error: error!" - no indication of where the exception came from
Observable.just(1).select(test).subscribe(on_error = lambda e: print("error: {0}".format(e)))

我想在on_错误处理程序中获得异常的起源

从我到目前为止所阅读的内容来看,Python2实际上没有任何方法纯粹从Exception对象获取堆栈跟踪

在不修改“test”函数本身的情况下,有没有办法做到这一点?rxpy本身是否提供了访问stacktrace的任何功能

谢谢


Tags: 方法fromtestimportondeffunctionfuture