[英]python cProfile giving 'int' object is not callable error
以下腳本運行很棒:
$ 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。 我知道它必須是非常小的東西,只是不能指出它。
請幫我解決。 謝謝
你有一個名為id
的整數變量,它掩蓋了內置函數id
。 這搞亂了cProfile
。
重命名你的id
變量, cProfile
應該可以正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.