Reputation: 51039
I would like to work with an interpreter, then when wish to stop, save it's entire state into file. I don't want to mind what to save. For example, I don't want to list variables. I want it to automatically save everything.
Tomorrow I wish to reopen saved state and continue operating from the same place.
Various notebooks like Jupyter are not applicable, because they only can re-execute my commands to restore state, which can take time, which I wish to avoid.
Any other mature interpreting language with this capability is appreciated.
Upvotes: 3
Views: 1820
Reputation: 178
I wrote an algorithm called a State Saving Interpreter, which saves the state of the List Prolog Interpreter (including variables and recursive states of predicates and commands) at https://github.com/luciangreen/SSI. I will use it to develop web apps and even an online Prolog interpreter. Prolog applications can be ported to the web, which needs the interpreter state to be saved to run applications.
Upvotes: 0
Reputation: 1425
You can use dill to save and load python interpreter sessions using dill.dump_session and dill.load_session.
From the docs:
dill
provides the ability to save the state of an interpreter session in a single command. Hence, it would be feasable to save a interpreter session, close the interpreter, ship the pickled file to another computer, open a new interpreter, unpickle the session and thus continue from the 'saved' state of the original interpreter session.
Example of using dump_session
❯ python
>>> def func(a):
... print(a)
>>> class MyClass:
... pass
>>> x,y,z = 1, "hello", [1,2,3]
>>> import dill
>>> dill.dump_session()
Load session:
❯ python
>>> import dill
>>> dill.load_session()
>>> x,y,z,func,MyClass
(1, 'hello', [1, 2, 3], <function func at 0x10d853d40>, <class '__main__.MyClass'>)
dill
cannot yet pickle some standard types, so you have to try yourself to see if it works for you.
Upvotes: 4