[Cython] Cython creates non-pickleable classes
Stefan Behnel
stefan_ml at behnel.de
Tue Jan 12 07:51:04 EST 2016
Hi Serhiy!
Serhiy Storchaka schrieb am 11.01.2016 um 21:32:
> Sorry, I'm not very familiar with Cython, but it looks to me that Cython
> creates extension classes that can't be correctly copied and unpickled.
> Since default __reduce_ex__ implementation knows nothing about Cython class
> structure, it's result doesn't contain the state of the object. The object
> could be pickled, but unpickled object doesn't contain original values of
> fields, it is just non-initialized. In recent CPython releases was added
> new restrictions for pickling objects that can't be correctly unpickled.
> This had added incompatibility with Cython classes. Building some packages
> now is failed, because Cython makes a deep copy that actually doesn't work.
>
> See for original changes and discussion about the regression:
> http://bugs.python.org/issue22995 .
>
> Besides the fact of Cython regression, it looks to me, that Cython also
> needs to be fixed. It can be done either by generating default
> pickle-related methods (__getnewargs__/__getnewargs_ex__, or __getstate__ +
> __setstate__, or __reduce__/__reduce_ex__) for all Cython classes, or
> implementing pickling or deepcopying only for NameAssignment and like.
Here's a call trace from the above ticket:
https://paste.debian.net/361351/
I can confirm that this is a bug in Cython (the compiler, not the code it
generates). There are a couple of classes (NameAssignment, its subclasses
and potentially others) that get deep-copied by the standard mechanism and
thus loose their internal object state. This should get fixed. It wasn't an
issue in practice because these objects aren't commonly used after this
copy, but there's no reason they couldn't be.
Stefan
More information about the cython-devel
mailing list