Is there anything that pickle + copy_reg cannot serialize?

Jean-Paul Calderone exarkun at divmod.com
Thu Dec 8 14:16:01 EST 2005


On Fri, 09 Dec 2005 02:17:10 +0800, Maurice LING <mauriceling at acm.org> wrote:
>
>> Since copy_reg lets you specify arbitrary code to serialize arbitrary
>> objects, you shouldn't run into any single object that you cannot
>> serialize to a pickle.
>
> [snip - example of pickling code objects]
>
>
>I cannot understand 2 things, which I seek assistance for:
>1. Is code object the only thing can cannot be pickled (less facing
>recursion limits)?

No.  There are lots of objects that cannot be pickled by default.  Any 
extension type which does not explicitly support it cannot be pickled.  
Generators cannot be pickled.  Method descriptors can't be pickled.  Et 
cetera.

>2. In the above example, how copy_reg works with pickle?

Any time pickle thinks it has found something it cannot pickle, it asks 
the copy_reg module for some help.  The above example basically teaches 
the copy_reg module how to give the pickle module the help it needs for 
code objects.

Jean-Paul



More information about the Python-list mailing list