尝试分析简单程序时出现 Python-Hotshot 错误
我试图学习如何使用 hotshot 分析一个简单的 python 程序,但遇到了一个奇怪的错误,
import sys
import hotshot
def main(argv):
for i in range(1,1000):
print i
if __name__ == "__main__":
prof = hotshot.Profile("hotshot_edi_stats")
b,c = prof.runcall(main(sys.argv))
prof.close()
并且输出,
.
.
995
996
997
998
999
Traceback (most recent call last):
File "t.py", line 9, in <module>
b, c = prof.runcall(main(sys.argv))
File "/usr/lib/python2.5/hotshot/__init__.py", line 76, in runcall
return self._prof.runcall(func, args, kw)
TypeError: 'NoneType' object is not callable
有人知道为什么会发生这种情况吗? 在我看来,这似乎是热点分析器本身的问题。 或者,人们对分析 python 程序的其他方法有建议吗?
谢谢!
I was trying to learn how to profile a simple python program using hotshot, but am facing a weird error,
import sys
import hotshot
def main(argv):
for i in range(1,1000):
print i
if __name__ == "__main__":
prof = hotshot.Profile("hotshot_edi_stats")
b,c = prof.runcall(main(sys.argv))
prof.close()
and the output,
.
.
995
996
997
998
999
Traceback (most recent call last):
File "t.py", line 9, in <module>
b, c = prof.runcall(main(sys.argv))
File "/usr/lib/python2.5/hotshot/__init__.py", line 76, in runcall
return self._prof.runcall(func, args, kw)
TypeError: 'NoneType' object is not callable
Would anyone know why this happens? It looks to me like a problem with the hotshot profiler itself. Alternatively, do people have suggestions on other methods to profile python programs?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想我已经找到了我错过了 2 个多小时的东西。
事实证明, runcall() 应该被调用为,
这使得事情可以正常工作!
And I think I've figured out something I missed for over 2 hours..
Turns out, runcall() should be called as,
and this makes things work!
一般来说,如果您有办法随机暂停或中断程序并查看调用堆栈,此方法始终有效。
In general, if you have a way to randomly pause or interrupt the program and see the call stack, this method always works.