How to save the status of the interpreter and send it to another machine where it can be restored?

Closed due to the fact that the essence of the question is not clear to the participants 0xdb , aleksandr barakin , freim , LFC , Yaant January 31 at 11:59 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What exactly do you mean by interpreter state? - Sergey Gornostaev
  • All that is possible. It is necessary for debugging, if it fell with an incomprehensible exception. Sometimes there is not enough information about variables. - Andru
  • To put it in a virtualka. At the right moment, the virtual machine will fall asleep and ship to another machine. There wake up. :) On the other hand, it has already fallen, what kind of variables are there ... - Akina
  • @Akina, there is such a programming language Euphoria. When the program crashes, the text of the error and the frame-rate are written to a file, and the state of (partial) local and global variables is also recorded there. The truth with data types there is not very rich - there are only numbers ("atoms") and the equivalent of Python lists (strings are a set of numbers in the list). A sort of procedural Lisp. Here, for debugging such a dump could be convenient, though in Python it is not always possible by repr to understand the state of the object. - insolor

1 answer 1

You can think of something like

import sys def dump_state(t, v, tb): if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(t, v, tb) else: import traceback from pprint import pprint traceback.print_exception(t, v, tb) with open('state.txt', 'w') as fh: while tb: pprint({ 'globals': tb.tb_frame.f_globals, 'locals': tb.tb_frame.f_locals }, stream=fh) tb = tb.tb_next sys.excepthook = dump_state 

After an unhandled exception is thrown, all global and local variables for state analysis will be in state.txt.

  • And if the locals push in the pickle and deploy to another machine? - eri
  • @eri yes there are lots of options that you can dump_state into the dump_state handler. Both in terms of data storage formats, and in terms of what exactly to save and how to use later. - Sergey Gornostaev