473,544 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pickle and __slots__

JL
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

Oct 4 '07 #1
3 4580
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
Oct 4 '07 #2
JL
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.dispat cher 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.dispat cher and asynchat.async_ chat
subclass instances which will not be relevant at unpickle time.

Oct 4 '07 #3
JL
I added the following method to the 2 subclasses of
asyncore.dispat cher and asynchat.async_ chat and now pickle works:

def __getstate__(se lf):
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.

Oct 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1165
by: Gonçalo Rodrigues | last post by:
Hi, Can I force the pickling/unpickling mechanism to call the class constructor? I thought __getinitargs__ would do the job, but the following shows it does not. >>> class Test(object): def __init__(self, **kwargs): super(Test, self).__init__(**kwargs) self.__dict__.update(kwargs)
16
3499
by: Nicolas Fleury | last post by:
Is it possible to use the pickle module to update an object instead of creating a new instance? Thx Nicolas
4
2627
by: Christos TZOTZIOY Georgiou | last post by:
__getstate__ is easy: def __getstate__(self): return tuple(self) but even def __getstate__(self): return self
8
8074
by: Hans Georg Krauthaeuser | last post by:
Dear all, I have a long running application (electromagnetic compatibility measurements in mode-stirred chambers over GPIB) that use pickle (cPickle) to autosave a class instance with all the measured data from time to time. At the beginning, pickling is quite fast but when the data becomes more and more pickling slows down rapidly.
1
1858
by: i_hate | last post by:
Hello, I've just discovered the hard way that classes declaring private variables (beginning with two underscore) can not be pickled ; double underscored attributes are just not returned by __reduce__. That's very annoying. Objects should be serializable transparently so why such obstacles ?
3
4499
by: dgdev | last post by:
I would like to pickle an extension type (written in pyrex). I have it working thus far by defining three methods: class C: # for pickling __getstate__(self): ... # make 'state_obj' return state_obj __reduce__(self):
27
1707
by: Licheng Fang | last post by:
Python is supposed to be readable, but after programming in Python for a while I find my Python programs can be more obfuscated than their C/C ++ counterparts sometimes. Part of the reason is that with heterogeneous lists/tuples at hand, I tend to stuff many things into the list and *assume* a structure of the list or tuple, instead of...
10
3471
by: krustymonkey | last post by:
I'm wondering if anyone can help with a workaround for a problem I currently have. I'm trying to set up a prefork tcp server. Specifically, I'm setting up a server that forks children and has them listen on pipes created with os.pipe(). The parent process for the group starts an inet:tcp server on a given port. In the parent, after a...
2
2475
by: scsoce | last post by:
got a exception: "a class that defines __slots__ without defining __getstate__ cannot be pickled " why? and is there any other dump method but for pickle to store the kind of object ?
0
7434
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7371
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7622
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7388
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3425
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3420
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.