Profiler throws NameError on any function

Philipp Lies philipp.lies at
Thu Mar 26 15:42:57 CET 2009


I'm trying to run the python profiler on some code but I always get
NameErrors, even for the simplest case taken from the docs:
import profile
def foo():
    a = 5
def prof():'foo()')

When I run prof() I get the following output:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 11, in prof'foo()')
  File "/usr/lib/python2.5/", line 70, in run
    prof =
  File "/usr/lib/python2.5/", line 456, in run
    return self.runctx(cmd, dict, dict)
  File "/usr/lib/python2.5/", line 462, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
NameError: name 'foo' is not defined
The very same error I get using cProfile.

It works when I call
profile.runctx('foo()', globals(), locals())
which should be the same as run('foo()'), shouldn't it?

I'm using python 2.5.2 on ubuntu 8.10.



More information about the Python-list mailing list