当肯定存在调用堆栈时,为什么traceback.extract_stack()会返回[]?
我有一个调用其 __init__()
的类
traceback.extract_stack()
,但每当我这样做时,traceback.extract_stack()
的值都是 []
。
造成这种情况的原因有哪些? 是否有另一种方法来获得更可靠的回溯?
我认为问题在于代码是在 Pylons 中运行的。 这是控制器操作的一些代码:
def test_tb(self):
import traceback
return a.lib.htmlencode(traceback.extract_stack())
它生成一个网页,所以
[]
,我认为它与对象的构造函数或类似的东西没有任何关系。 它是否与某些类型的线程和回溯模块或类似的东西之间的不兼容有关?
I have a class that calls
traceback.extract_stack()
in its __init__()
, but whenever I do that, the value of traceback.extract_stack()
is []
.
What are some reasons that this could be the case?
Is there another way to get a traceback that will be more reliable?
I think the problem is that the code is running in Pylons. Here is some code for a controller action:
def test_tb(self):
import traceback
return a.lib.htmlencode(traceback.extract_stack())
It generates a webpage that is just
[]
So, I don't think it has anything to do with being in the constructor of an object or anything like that. Could it have to do with an incompatibility between some kinds of threading and the traceback module or something like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面显示了从类的 __init__ 方法调用时traceback.extract_stack() 的工作情况。 请发布您的代码,表明它不起作用。 包括 Python 版本。 不要凭记忆打字; 像我一样使用复制/粘贴。
更新不要查看
return a.lib.htmlencode(traceback.extract_stack())
并想知道,而是进入管道:(1) do
tb_stack = repr ((traceback.extract_stack())
并将结果写入日志文件以进行检查(2) 执行
return a.lib.htmlencode(some_known_constant_data)
并检查已知数据是否正确显示您期望它出现的地方。Following shows traceback.extract_stack() working when called from a class's
__init__
method. Please post your code showing that it doesn't work. Include the Python version. Don't type from memory; use copy/paste as I have done.UPDATE Instead of looking at
return a.lib.htmlencode(traceback.extract_stack())
and wondering, tap into the pipeline:(1) do
tb_stack = repr((traceback.extract_stack())
and write the result to your logfile for checking(2) do
return a.lib.htmlencode(some_known_constant_data)
and check that the known data shows up correctly where you expect it to show up.查看回溯模块的代码,一种可能性是您已将 sys.tracebacklimit 设置为零,尽管这看起来不太可能......
Looking at the code for the traceback module, one possibility is that you've got sys.tracebacklimit set to zero, though that seems like a longshot...
原因原来是有人在项目上打开了 Pysco,而 Psyco 与回溯模块配合得不好。
The reason turned out to be that someone turned on Pysco on the project, and Psyco doesn't play nice with the traceback module.