merote
merote

Reputation: 55

cProfile.run() isn't doing anything

This is probably a stupid question but I've spent 2 hours researching this problem and seem to be the only person with it.

import cProfile
cProfile.run('import game; game.main()')

All this does is run and return the game.main() function. The result is no different than running game.main() without cProfile. But everyone else on the internet seems to get a nice, neat table of data from the virtually identical code. What am I doing wrong.

Upvotes: 0

Views: 955

Answers (1)

Bakuriu
Bakuriu

Reputation: 102039

cProfile.run does produce a table with profiling statistics when the code snippet ends. In your case the call to game.main() is an infinite loop, so cProfile will simply run the loop until it stops for some reason.

You can try to break out of an infinite loop by pressing Ctrl+C which will raise a KeyboardInterrupt exception in the program. When the program exits you'll see the table of the statistics (and also the traceback of the exception).

Upvotes: 1

Related Questions