是否可以将 Python 解释器的状态保存到文件中? [英] Is it possible to save the Python interpreter's state to a file?

查看:36
本文介绍了是否可以将 Python 解释器的状态保存到文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果当用户使用我的 Python 应用程序并且应用程序崩溃时,应用程序的状态可以保存到一个文件并发送给我,开发人员怎么办?我打开 Python 解释器,从用户崩溃的地方开始调试.

What if, when a user is using my Python application and the application crashes, the state of the application can be saved to a file and sent to me, the developer? I open the Python interpreter and start debugging from the point where the user crashed.

澄清一下,当我调试应用程序并引发未处理的异常时,我可以事后调试应用程序,访问所有局部变量及其值,这对于快速修复错误至关重要.但是,当用户的应用程序崩溃时,我只会收到错误发生时的堆栈跟踪,这很有帮助,但不如交互式调试那么多.

To clarify, when I'm debugging an application and it raises an unhandled exception, I can debug the application post-mortem, getting access to all the local variables and their values which is crucial to quickly fixing bugs. When an user's application crashes though, I only receive the stack trace for when the error occurred, which is helpful, but not nearly as much as debugging interactively would be.

那么是否可以将 Python 应用程序的状态保存到文件中,关闭解释器,然后在稍后阶段从该文件恢复执行?

So is it possible to save the state of a Python application to a file, close the interpreter, then resume the execution from that file at a later stage?

推荐答案

这个工具可能会有所帮助,但是当发生异常时,您需要在代码中调用转储程序.它只是腌制回溯 &框架对象到文件中

This tool may help, but you'll need to call the dumper in your code when exception happens. It simply pickles the traceback & frame objects into files

还有一个类似的问题 这里.

And there's a similar question here.

这篇关于是否可以将 Python 解释器的状态保存到文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆