Python profiler usage with objects

rik rbelew at ucsd.edu
Wed Jun 30 02:39:25 EDT 2010


Ben Kaplan <bsk16 <at> case.edu> writes:
 
> 
> Let's take this code as an example:
> 
> def foo() :
>     return None
> 
> import profile
> profile.run(foo())
> 
> What does the profile.run call do?
> 
> First thin it does is evaluate foo(), which returns None. So you're calling
> profile.run(None)
> 
> There's  nothing special about profile.run- you have to hand it something to
> execute, not something already executed. Try calling
> Profile.run(doSomething) # no parenthesis for doSomething.
> > 
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 

hi Ben,  right: i have a top-level function main() that runs just
fine.  but i give it as an argument to cProfile.run() or profile.run(),
it executes as expected, but then:

>   File "/var/folders/lu/luGJNSGwE0mO84R+YbcKpU+++TI/-Tmp-/python-439Ffi.py",
line 544, in ?
>     profile.run(main(seedFile),'/Data/tmp/fetchProfile_100629.profile')
>   File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/profile.py",
line 72, in run
>     prof = prof.run(statement)
>   File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/profile.py",
line 448, in run
>     return self.runctx(cmd, dict, dict)
>   File
"/Library/Frameworks/Python.framework/Versions/2.4//lib/python2.4/profile.py",
line 454, in runctx
>     exec cmd in globals, locals
> TypeError: exec: arg 1 must be a string, file, or code object

this example is from python2.4 on OSX, but the same code generates
the same error on python2.6 on Ubuntu?!  








More information about the Python-list mailing list