Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1028779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:26:40+00:00 2026-05-16T12:26:40+00:00

I have a large instance that I’ve been pickling just fine, but recently I

  • 0

I have a large instance that I’ve been pickling just fine, but recently I started getting this error when I tried to dump it:

  File "/usr/lib/python2.6/copy_reg.py", line 77, in _reduce_ex
    raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled

I don’t understand this error, since all my classes seem to define a __getstate__ method, and none seem to define __slots__. I’m having trouble isolating the change I made the triggered this error.

I can only assume there’s some object nested deep within my instance that’s causing this. Is there any way to get more info? How do I find the class of the exact object that’s triggering this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T12:26:40+00:00Added an answer on May 16, 2026 at 12:26 pm

    Use a binary protocol for your pickling (instead of the old ASCII one you seem to be defaulting to) and you’ll be fine. Observe:

    >>> class ws(object):
    ...   __slots__ = 'a', 'b'
    ...   def __init__(self, a=23, b=45): self.a, self.b = a, b
    ... 
    >>> x = ws()
    >>> import pickle
    >>> pickle.dumps(x, -1)
    '\x80\x02c__main__\nws\nq\x00)\x81q\x01N}q\x02(U\x01aq\x03K\x17U\x01bq\x04K-u\x86q\x05b.'
    >>> pickle.dumps(x)
    Traceback (most recent call last):
        [[snip]]
      File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/copy_reg.py", line 77, in _reduce_ex
        raise TypeError("a class that defines __slots__ without "
    TypeError: a class that defines __slots__ without defining __getstate__ cannot be pickled
    >>> 
    

    As you see, the -1 protocol (which means “the best, fastest and most compact protocol”) works just fine, while the default 0 protocol (the old ascii protocol designed to be compatible all the way back to Python 1.5 and earlier) gives exactly the exception you have observed.

    Besides, -1 will be faster and produce more compact results — you just need to ensure you correctly save and restore the binary strings it produces (so, for example, if you’re pickling to file, be sure to open the latter for wb, not just w).

    If for some reason this all-around-win solution is not available to you, there are hacks and tricks (e.g., subclass pickle.Pickler, use directly an instance of your subclass rather than the base one as pickle.dumps does, override the save method so it traces the type(obj) before delegating to the superclass), but upgrading to the right, most up-to-date protocol (-1 is guaranteed to be, on any given Python version, the most advanced one that version supports) would be a good idea anyway, if at all feasible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Swing app that processes relatively large amounts of data. For instance
I have large batches of XHTML files that are manually updated. During the review
I'm developing a website in PHP and I have large JS files that I
I have a large codebase that targetted Flash 7, with a lot of AS2
I have a large database and would like to select table names that have
We have a large (>500,000 LOC) Java system that depends on 40-50 OSS packages.
I have a large PHP loop that I'm re-using in multiple spots on multiple
I have large data files stored in S3 that I need to analyze. Each
we have a large ec2 instance running in asia pacific region.we want to reserve
I have a large amount of Word documents that I need to parse. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.