Profile this

By Filip Salo; published on September 03, 2009. Tags: bugs profiling python

Consider a very small python program, test.py:

label = "foo"

And then consider profiling that program with the very nice cProfile module:

$ python -m cProfile test.py

Finally, consider the consequences:

Traceback (most recent call last):
  File ".../lib/python2.5/runpy.py", line 95, in run_module
    filename, loader, alter_sys)
  File ".../lib/python2.5/runpy.py", line 52, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File ".../lib/python2.5/runpy.py", line 32, in _run_code
    exec code in run_globals
  File ".../lib/python2.5/cProfile.py", line 190, in <module>
    main()
  File ".../lib/python2.5/cProfile.py", line 183, in main
    run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
  File ".../lib/python2.5/cProfile.py", line 36, in run
    result = prof.print_stats(sort)
  File ".../lib/python2.5/cProfile.py", line 81, in print_stats
    pstats.Stats(self).strip_dirs().sort_stats(sort).print_stats()
  File ".../lib/python2.5/pstats.py", line 92, in __init__
    self.init(arg)
  File ".../lib/python2.5/pstats.py", line 106, in init
    self.load_stats(arg)
  File ".../lib/python2.5/pstats.py", line 130, in load_stats
    arg.create_stats()
  File ".../lib/python2.5/cProfile.py", line 92, in create_stats
    self.snapshot_stats()
  File ".../lib/python2.5/cProfile.py", line 100, in snapshot_stats
    func = label(entry.code)
TypeError: 'str' object is not callable

(File paths shortened because mine are horribly long.)

Now consider stabbing your heart out with a fork. Though perhaps I should see if I can fix it instead, and submit a patch.