views:

184

answers:

2

Hi all,

I was trying to learn how to profile a simple python program using hotshot, but am facing a weird error,

import sys
import hotshot
def main(argv):
  for i in range(1,1000):
    print i

if __name__ == "__main__":
  prof = hotshot.Profile("hotshot_edi_stats")
  b,c = prof.runcall(main(sys.argv))
  prof.close()

and the output,

.
.

995
996
997
998
999
Traceback (most recent call last):
  File "t.py", line 9, in <module>
    b, c = prof.runcall(main(sys.argv))
  File "/usr/lib/python2.5/hotshot/__init__.py", line 76, in runcall
    return self._prof.runcall(func, args, kw)
TypeError: 'NoneType' object is not callable

Would anyone know why this happens? It looks to me like a problem with the hotshot profiler itself. Alternatively, do people have suggestions on other methods to profile python programs?

Thanks!

+2  A: 

And I think I've figured out something I missed for over 2 hours..

Turns out, runcall() should be called as,

runcall(main, self.argv)

and this makes things work!

viksit
+1 Good job figuring out by yourself
kender
+1  A: 

In general, if you have a way to randomly pause or interrupt the program and see the call stack, this method always works.

Mike Dunlavey
Nice! I like the bayesian debug theory :)
viksit