Is it possible to save a running program and reload next time ?

Hans Georg Krauthaeuser hgk at et.uni-magdeburg.de
Fri Sep 22 02:36:47 EDT 2006


fdu.xiaojf at gmail.com wrote:
> Hans Georg Krauthaeuser wrote:
>> fdu.xiaojf at gmail.com wrote:
>>  
>>> Can objects be saved and reloaded by "Pickle"  ?  I have tried but no
>>> success.
>>>
>>>     
>> Yes, that's the intended use of pickle/cPickle. There are examples in
>> the docs:
>>
>> http://docs.python.org/lib/module-pickle.html
>>
>> What have you tried and what didn't work?
>>
>> Hans Georg
>>   
> My program is a genetic algorithm based program, so I thought I just
> need to save a generation object of the population and reload it later
> then my program could continue. But after I saved a generation object
> from within python using cPickle and reload it from another program, it
> said that some class object couldn't be found. Now I realized that a
> program cannot be suspended and reloaded by just simply dumping and
> loading using cPickle/Pickle.
> 
> I will try stackless python later.
> 
> Thanks a lot .
> 
> Regards,
> 
> xiaojf
> 
I use pickle to periodically save measured data for measurements that
take several days to finish. Actually, I save a class instance with the
data, the measurement methods and additional informations what method
was called and with what parameters. If the measurement crashes due to
some reasons, I recreate the class instance from the pickle file, call
the appropriate method with the saved parameters. Then, the method has
to look what data is already there and will continue to measure the rest.

I have no idea whether that will help you in your situation.

Anyway, I wish you all the best.

Hans Georg



More information about the Python-list mailing list