dumping in destructor

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Oct 22 00:04:06 EDT 2008


En Tue, 21 Oct 2008 10:31:58 -0200, Митя <netimen at gmail.com> escribió:

> Thank you! I have already implemented custom load/save operations
> without pickle. And they work fine on atexit.
>
> Just for information: pickle.dump worked OK when called manually, but
> being called by atexit it produeced the above described error. I don't
> know why.

This small example (based on your code) worked fine for me:

import atexit
 from pickle import dump

class _Register(object):
    def dump(self):
      dump(self.items, open("x.xxx","wb"), -1)

class Registerable(object):
    pass

g_register = _Register()
atexit.register(g_register.dump)
g_register.items = [Registerable(),Registerable()]

-- 
Gabriel Genellina




More information about the Python-list mailing list