意外中断的cProfile

时间:2019-07-16 17:25:44

标签: python recovery keyboardinterrupt

经过长时间的函数调用(16个小时)后,我以KeyboardInterrupt提前结束了它,但是偶然地也中断了cProfile,因为响应时间太长了。在Debug Stackviewer中,我遇到了这个问题:

  • KeyboardInterrupt:
    • idlelib.run.runco​​de(...)
    • __主__。<模块>(...)
    • 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(...)

有没有办法恢复cProfile要打印的内容,并且有一种方法可以更聪明地将cProfile用于过长的函数调用。

1 个答案:

答案 0 :(得分:1)

否,该过程退出时,所有捕获的信息都会丢失。您可以考虑使用profiling软件包,该软件包在程序运行时提供配置文件输出。我一直打算将其用于一些交互式程序。