3

次のスクリプトはうまく動作します:

$ 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をチョークすることを除いて、両方の場合で正常に実行されます。私はそれが本当にささいなことでなければならないことを知っています、ただそれを釘付けにすることはできません.

解決を手伝ってください。ありがとう

4

1 に答える 1

6

id組み込み関数 をマスクしているという名前の整数変数がありますid。それはめちゃくちゃcProfileです。

id変数の名前を変更すると、正常にcProfile動作するはずです。

于 2011-09-20T18:43:22.713 に答える