Profile this

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

Consider a very small python program,

label = "foo"

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

$ python -m cProfile

Finally, consider the consequences:

Traceback (most recent call last):
  File ".../lib/python2.5/", line 95, in run_module
    filename, loader, alter_sys)
  File ".../lib/python2.5/", line 52, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File ".../lib/python2.5/", line 32, in _run_code
    exec code in run_globals
  File ".../lib/python2.5/", line 190, in <module>
  File ".../lib/python2.5/", line 183, in main
    run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort)
  File ".../lib/python2.5/", line 36, in run
    result = prof.print_stats(sort)
  File ".../lib/python2.5/", line 81, in print_stats
  File ".../lib/python2.5/", line 92, in __init__
  File ".../lib/python2.5/", line 106, in init
  File ".../lib/python2.5/", line 130, in load_stats
  File ".../lib/python2.5/", line 92, in create_stats
  File ".../lib/python2.5/", 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.