On Mon, 20 Oct 2008 01:12:06 -0700, Митя wrote: > I have a class which I want to save it's data automatically on disc, > when it's destroyed. I have following code: > > from cPickle import dump > > class __Register(object): > def __init__(self): > self.dict = {} > def __del__(self): > fh = open('aaa', 'w') > dump(self.dict, fh) > fh.close() > > g_register = __Register() # global instance. I do not destroy it > manually, so destructor is called on iterpreter exit
The call to `__del__()` is not guaranteed. > can I somehow save my data from destructor? Reliably? No! Change your design, it won't work this way. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list