简体   繁体   English

给出'int'对象的python cProfile是不可调用的错误

[英]python cProfile giving 'int' object is not callable error

Following script runs great: 以下脚本运行很棒:

$ python myscript.py 

When I try to profile my code using cProfile like: 当我尝试使用cProfile配置我的代码时:

$ 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. 我的脚本在两种情况下都成功运行,只是在后一种情况下它会阻塞cProfile。 I know it has to be something really petty, just cant nail it. 我知道它必须是非常小的东西,只是不能指出它。

Please help me resolve. 请帮我解决。 Thanks 谢谢

You have an integer variable named id that is masking the built-in function id . 你有一个名为id的整数变量,它掩盖了内置函数id That is messing up cProfile . 这搞乱了cProfile

Rename your id variable and cProfile should work fine. 重命名你的id变量, cProfile应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM