First off I’m not expecting a solution, just hoping for some pointers on how to start.
I’ve got a C program with an embedded Python interpreter. The Python scripts the program uses as input obviously refer to the C-defined objects and functions. I’d now like to make some of these objects pickleable.
The pickle docs describe how extension types can be made picklable using __reduce__. But this is a Python method – how would I define this in the underlying PyObject?
Fairly sure I’m mis-understanding something…
The
picklemodule comes in both a python-only and a C variant (calledcPickle). As such, the__reduce__method needs to be callable from Python code.Thus, you need to provide a
__reduce__entry in your C objectPyMethodDefstruct with a suitable implementation.Alternatively, you can also register a pickling function with the
copy_regmodule. This module’s original usecase was to support extension modules better; the source code for the module states: