New submission from sbt <[email protected]>:
Currently the only documented way to have customised pickling for a type is to
register a reduction function with the global dispatch table managed by the
copyreg module. But such global changes are liable to disrupt other code which
uses pickling.
Multiprocessing deals with this by defining a ForkingPickler class which
subclasses the pure python _Pickler class (using undocumented features), and
supports registering reduction functions specifically for that class.
I would like to see some documented alternative which works with both C and
Python implementations. At least then multiprocessing can avoid using slow
pure python pickling.
The attached patch allows a pickler object to have a private dispatch table
which it uses *instead* of the global one. It lets one write code like
p = pickle.Pickler(...)
p.dispatch_table = copyreg.dispatch_table.copy()
p.dispatch_table[SomeClass] = reduce_SomeClass
or
class MyPickler(pickle.Pickler):
dispatch_table = copyreg.dispatch_table.copy()
MyPickler.dispatch_table[SomeClass] = reduce_SomeClass
p = MyPickler(...)
The equivalent using copyreg would be
copyreg.pickle(SomeClass, reduce_SomeClass)
p = pickle.Pickler(...)
----------
files: pickle_dispatch.patch
keywords: patch
messages: 154695
nosy: sbt
priority: normal
severity: normal
status: open
title: private dispatch table for picklers
type: enhancement
versions: Python 3.3
Added file: http://bugs.python.org/file24697/pickle_dispatch.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue14166>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com