Code execution snapshot

I’m trying to make prototype of python library to save code execution (globals, locals, filename, line_no) to disk or variable, to be able further rollback execution back to the point. How to implement it, if inspect.getcurrentframe() blocks set requests into frame, it is immutable.

Is there proper way to save current call stack and globals/locals for each frame, so it can be restored further from the line where program stopped?

I’m trying to implement execution checkpoints (snapshots/time_travel) with save_state() and load_state() funcs. There are pickle and dill to save globals and locals, but I don’t see the way to save/resume execution frames stack.

(Maybe inspection.get_currentframe() will help to save line_no and code filename recursive until f_back is None, but I don’t know how to restore saved data in right way.)

How accurately do you need to be able to roll everything back? It may be impractical to do anything less than a full snapshot of process memory. For example, you may very well need to roll back mutations to other objects; do you also need to roll back the internal state of the PRNG?

The dill module has a method to sort of do this: dill package documentation — dill 0.3.8.dev0 documentation

It will have some misses but may be a place to start or good enough.