22

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.

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?

Hubro
  • 56,214
  • 69
  • 228
  • 381
  • possible duplicate of [How to save a Python interactive session?](http://stackoverflow.com/questions/947810/how-to-save-a-python-interactive-session) – Ashwini Chaudhary Jan 25 '13 at 09:49
  • 3
    @AshwiniChaudhary: I don't think this is an *exact duplicate* of that question. This is a question about saving the entire state of the interpreter and resuming it at a later point in time, not about saving the current settings and locals from the interactive interpreter. – Hubro Jan 25 '13 at 09:53
  • 1
    You are probably looking for something similar to this [Recipe in ActiveState](http://code.activestate.com/recipes/572213-pickle-the-interactive-interpreter-state/) – Abhijit Jan 25 '13 at 10:03

1 Answers1

7

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.

Community
  • 1
  • 1
l04m33
  • 586
  • 3
  • 12