Discovery of unpickleables in class heirarchies.

Brian L. Troutwine goofyheadedpunk at gmail.com
Fri Jun 22 10:01:07 EDT 2007


I've a need to pickle arbitrary class hierarchies, which, luckily, can
be made to conform to the pickle protocol. At the moment, however, I'm
having a rather hard time discovering which classes in a heirarchy
cannot be pickles. For instance, say class A has class B in it's
__dict__ and let class B have a file handler in its __dict__. When I
call cPickle.dumps(A) UnpickleableError will be raised when B's file
handler is reached, but the error will only report being unable to
pickle the file handler, saying nothing of B or A. I wouldn't expect
cPickle to do that, but I do need to know somehow that class B has
failed to pickle properly.

To that end I've quickly hacked out a class that, ideally, will take
an object that I'm attempting to pickle and, if the pickling does not
succeed, recurse through the class heirarchy collecting information on
which objects were not pickled. It is here: http://deadbeefbabe.org/paste/5218
The output, for the above example would be:

<type 'A'>
  <type 'B'>
    <type 'file'>

However, it seems to be taking a rather long time. Perhaps my class
heirarchies are too deep, or my recursion is flawed. Can anyone see a
bug in my code, or have a better way of discovering this information
altogether?




More information about the Python-list mailing list