Search code examples
pythonrecoverykeyboardinterrupt

Accidentally Interrupted cProfile


After a long function call (16 hours), I ended it early with KeyboardInterrupt, but accidentally also interrupted cProfile, because it was taking so long to respond. In the Debug Stackviewer, I am faced with this:

  • KeyboardInterrupt:
    • idlelib.run.runcode (...)
    • __ main __.< module > (...)
    • cProfile.run (...)
    • profile.run (...)
    • profile._show (...)
    • cProfile.print_stats (...)
    • importlib._bootstrap._find_and_load (...)
    • importlib._bootstrap._find_and_load_unlocked (...)
    • importlib._bootstrap.find_spec (...)
    • importlib._bootstrap._get_spec (...)
    • importlib._bootstrap.find_spec (...)
    • importlib._bootstrap._path_stat (...)

Is there any way to recover what cProfile would have printed, and is there a way to more smartly use cProfile for excessively long function calls.


Solution

  • No, all captured information was lost when the process exited. You might consider using the profiling package that provides profile output while your program runs. I have been intending to use it with some of my interactive programs.