Reputation: 7752
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!
Upvotes: 2
Views: 756
Reputation: 40669
In general, if you have a way to randomly pause or interrupt the program and see the call stack, this method always works.
Upvotes: 1
Reputation: 7752
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!
Upvotes: 3