python cProfile 给出“int”;对象不可调用错误
以下脚本运行良好:
$ python myscript.py
当我尝试使用 cProfile 分析我的代码时,例如:
$ python -m cProfile -s time myscript.py
或
$ python -m cProfile myscript.py
出现以下错误:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 121, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 190, in <module>
main()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 183, in main
run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 36, in run
result = prof.print_stats(sort)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 81, in print_stats
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 92, in __init__
self.init(arg)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 106, in init
self.load_stats(arg)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 130, in load_stats
arg.create_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 92, in create_stats
self.snapshot_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 106, in snapshot_stats
callersdicts[id(entry.code)] = callers
TypeError: 'int' object is not callable
我的脚本在这两种情况下都成功运行,只是在后一种情况下它会阻塞 cProfile。我知道这一定是一些非常琐碎的事情,只是无法确定。
请帮我解决。谢谢
Following script runs great:
$ python myscript.py
When I try to profile my code using cProfile like:
$ python -m cProfile -s time myscript.py
or
$ python -m cProfile myscript.py
I get following error:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 121, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 190, in <module>
main()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 183, in main
run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 36, in run
result = prof.print_stats(sort)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 81, in print_stats
pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 92, in __init__
self.init(arg)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 106, in init
self.load_stats(arg)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/pstats.py", line 130, in load_stats
arg.create_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 92, in create_stats
self.snapshot_stats()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cProfile.py", line 106, in snapshot_stats
callersdicts[id(entry.code)] = callers
TypeError: 'int' object is not callable
My script runs successfully in both the cases except that it chokes cProfile in latter case. I know it has to be something really petty, just cant nail it.
Please help me resolve. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有一个名为
id
的整数变量,它屏蔽了内置函数id
。这搞乱了cProfile
。重命名您的 id 变量和 cProfile 应该可以正常工作。
You have an integer variable named
id
that is masking the built-in functionid
. That is messing upcProfile
.Rename your
id
variable andcProfile
should work fine.