Reputation: 763
Lets say I have a python program that does following:
do_some_long_data_crunching_computation()
call_some_fiddly_new_crashing_function()
Is there a way to "freeze" and serialize the state of python program (all globals and such) after the return point of first long computation and then re-iterate your development of new function and restart the program execution from this point?
This is somewhat possible, if you are running the program from the interpreter, but is there any other way?
Upvotes: 0
Views: 85
Reputation: 36452
Well, no.
The point is that Python and your OS aren't free of side effects (it really isn't even remotely functional, though it has some features of functional languages), so to restore the state of your program doesn't really work in this case. You'd basically have to re-run the program, with exactly the computer state you had when you started it the last time.
Now, what you'd do is that after your long operation, you could save the state of the variables that are important to you, using pickle
or similar.
Now, I know you'd like to avoid taking care of what to store and how to restore it, but that's basically a sign of unclean design: You should, as far as possible, store the state of your computation in a single state object; serializing and unserializing that then would be easy. Don't store computational state in globals!
Upvotes: 1