pickle and __slots__ - Python

This is a discussion on pickle and __slots__ - Python ; Hello, I am trying to pickle an object, and I get: TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled I didn't find __slots__ in the object or the class. Is there a way to find it, ...

+ Reply to Thread
Results 1 to 4 of 4

pickle and __slots__

  1. Default pickle and __slots__

    Hello,

    I am trying to pickle an object, and I get:

    TypeError: a class that defines __slots__ without defining
    __getstate__ cannot be pickled

    I didn't find __slots__ in the object or the class. Is there a way to
    find it, or to to know which object or class causes the problem?

    Thanks


  2. Default Re: pickle and __slots__

    JL wrote:
    > Hello,
    >
    > I am trying to pickle an object, and I get:
    >
    > TypeError: a class that defines __slots__ without defining
    > __getstate__ cannot be pickled
    >
    > I didn't find __slots__ in the object or the class. Is there a way to
    > find it, or to to know which object or class causes the problem?
    >
    > Thanks
    >

    Is this a subclass? Look at the parent classes.

    John Nagle

  3. Default Re: pickle and __slots__

    > Is this a subclass? Look at the parent classes.

    Its class is a subclass of a similar class, but it indirectly
    references instances of subclasses of asyncore.dispatcher or
    asynchat.async_chat. I don't think there are other particular classes.
    If I remove the first references, pickle works. Anyway it seems that I
    will have to mask the asyncore.dispatcher and asynchat.async_chat
    subclass instances which will not be relevant at unpickle time.


  4. Default Re: pickle and __slots__

    I added the following method to the 2 subclasses of
    asyncore.dispatcher and asynchat.async_chat and now pickle works:

    def __getstate__(self):
    return

    Later I will probably modify this method so it returns something more
    interesting.
    Thanks for your help! I was confused because I am not sure what can be
    pickled or not.


+ Reply to Thread

Similar Threads

  1. marshal vs pickle
    By Application Development in forum Python
    Replies: 15
    Last Post: 11-02-2007, 02:36 PM
  2. Re: marshal vs pickle
    By Application Development in forum Python
    Replies: 0
    Last Post: 11-01-2007, 04:34 PM
  3. Re: marshal vs pickle
    By Application Development in forum Python
    Replies: 0
    Last Post: 11-01-2007, 03:59 PM
  4. ValueError: insecure string pickle ?
    By Application Development in forum Python
    Replies: 2
    Last Post: 09-11-2007, 01:51 PM
  5. problem with pickle
    By Application Development in forum Python
    Replies: 1
    Last Post: 07-07-2007, 12:59 PM