Is there anything that pickle + copy_reg cannot serialize?
Maurice LING
mauriceling at acm.org
Fri Dec 9 06:08:24 EST 2005
>>> 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.
Thank Jean-Paul.
Sorry for not specifying clearly enough. Given that copy_reg lets you
specify arbitrary code to serialize arbitrary objects, of which some are
taken care of by pickle, in the set of possible Python types,
>>> import types
>>> dir(types)
['BooleanType', 'BufferType', 'BuiltinFunctionType',
'BuiltinMethodType', 'ClassType', 'CodeType', 'ComplexType',
'DictProxyType', 'DictType', 'DictionaryType', 'EllipsisType',
'FileType', 'FloatType', 'FrameType', 'FunctionType', 'GeneratorType',
'InstanceType', 'IntType', 'LambdaType', 'ListType', 'LongType',
'MethodType', 'ModuleType', 'NoneType', 'NotImplementedType',
'ObjectType', 'SliceType', 'StringType', 'StringTypes', 'TracebackType',
'TupleType', 'TypeType', 'UnboundMethodType', 'UnicodeType',
'XRangeType', '__builtins__', '__doc__', '__file__', '__name__']
What types cannot be serialized by pickle (besides CodeType) and
requires handling using copy_reg?
Thanks
Maurice
>
>> 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