[Pyrex] pickling pyrex classes

Robert Kern robert.kern at gmail.com
Mon Mar 26 19:43:04 UTC 2007


Brian Blais wrote:
> Hello,
> 
> I have a class defined in Pyrex (to get speed increases), and python complains that 
> is can't be pickled (class def included below).  I looked the documentation, and see 
> that I can define __setstate__ and __getstate__ methods to pickle only certain 
> methods/class variables.  Unfortunately, I am not clear on which ones are causing the 
> problem, so I figured I'd ask on the list before doing trial-and-error.  I imagine it 
> might be the "double *" , and perhaps the cdef methods, but I am not sure.

There's no reliable way for the pickle machinery to introspect extension type
instances like it does pure Python instances. Consequently, I believe that it
simply throws up its hands unless if you have defined the appropriate protocol
methods. No particular attribute is causing a problem, I don't think.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Pyrex mailing list