Persistence

Chris Liechti cliechti at gmx.net
Fri Apr 12 14:56:41 EDT 2002


Fernando Pérez <fperez528 at yahoo.com> wrote in
news:a959s9$s08$1 at peabody.colorado.edu: 

> Chris Liechti wrote:
> 
>> Rajarshi Guha <rxg218 at psu.edu> wrote in
>> news:a94qk5$22mg at r02n01.cac.psu.edu:
>> 
>>> On Thursday 11 April 2002 13:58 in comp.lang.python Riccardo de
>>> Maria wrote:
>>> 
>>>> Is there a way to save in a file the status, objects, functions of
>>>> interpreter
>>>> in order to restore it after the interpreter has been closed?
>>>> 
>>>> If it is possible, one can work on a project stop and then continue
>>>> later adding functions, objects and so on.
>> 
>> thats a question for an IDE with such functionality. i don't know one
>> but i think it should be easy to store all objects in the global
>> namespace of the interpreter and load it again on next startup.
>> the textual history of the interpreter with all the outputs must be
>> saved separately.
>> 
> 
> well, I've tried (not terribly hard) and failed. My ipython project is
> a fancy interpreter (http://www-hep.colorado.edu/~fperez/ipython/) and
> I wanted exactly that kind of functionality. It turns out pickle cant
> quite pickle _everything_ you throw at it, so there's bound to be
> things in your namespaces that you can't pickle.

i think PYRO.sf.net has solved some of the issues. Irmen says that he 
transmits missing code objects/class definitions to the remote machine
if it misses them. but i don't know if it works only with pyc files or with 
any class including those that were defined interactively. (the marshal 
module helps transfering pyc files (but code objects - well it seems so 
when i look at the docs?))
 
> I'd like to know if there's a way to make this work, because as I said
> my first attempts didn't get me anywhere. My kludgy semi-solution was
> to implement session logging/restore by replaying all input, but
> that's slow, error prone and has many other limitations.

in editors like PythonWin we could just replace the text in the interactive
console and unpickle/unmarshal the namespace.
maybe some special treatment is needed so that only code object are 
marshalled and instances are pickled.

i have not yet used pickle or marshal for real apps but its worth a try :-)
 
chris

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list