Thank you for your answers! my g_register is a global object, and it lives all the program's lifetime, so 'with' is not appliable. Am I right?
I tried to use atexit and wrote following: class _Register(object): def dump(self): .... class Registerable(object): .... g_register = _Register() atexit.register(g_register.dump) ... ... g_register.add(Registerable('aa')) But now I get: cPickle.PicklingError: Can't pickle <class '__main__.Registerable'>: attribute lookup __main__.Registerable failed Does that mean that by the time of atexit execution my Registerable class is already dead? Michele Simionato wrote: > On Oct 20, 10:12�am, ���� <[EMAIL PROTECTED]> wrote: > > But when g_register is being destroyed, dump seems to be already dead, > > so I get: > > > > Exception exceptions.TypeError: "'NoneType' object is not callable" in > > <bound method __Register.__del__ of <MyWiki.Register.__Register object > > at 0x835a74c>> ignored > > > > can I somehow save my data from destructor? > > The best thing is to use the 'with' statement, but it requires you to > rewrite all > of your code. Alternatively you can use the atexit module. I wrote > once a > recipe that may be of interest to you: > > http://code.activestate.com/recipes/523007/ -- http://mail.python.org/mailman/listinfo/python-list