pickle problem | Bytes (2024)

krustymonkey

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 "socket.accept( )", I'm trying to pickle the connection object to
send over an IPC pipe (as stated previously), but I get the following
error:

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

Does anyone know of a workaround for this? Maybe my approach to this
is wrong? Any help would be appreciated.

Jay

Jun 27 '08

Subscribe Reply

10 pickle problem | Bytes (1) 3479 pickle problem | Bytes (2)

  • <
  • 1
  • 2

castironpi

On May 11, 6:21*pm, krustymon...@gm ail.com wrote:

On May 8, 7:29 pm, castiro...@gmai l.com wrote:
On May 8, 4:35 pm, Hrvoje Niksic <hnik...@xemacs .orgwrote:
Marc 'BlackJack' Rintsch <bj_...@gmx.net writes:
On Thu, 08 May 2008 08:55:35 -0700, krustymonkey wrote:
The thing is, I'm not using slots by choice. *I'm using the standard
lib "socket" class, which apparently uses slots.
`socket` objects can't be pickled. *Not just because of the
`__slot__`\s but because a substantial part of their state lives in
the operating system's space.
Of course, if it makes sense to pickle sockets in the application, one
is can do so by defining __getstate__ and __setstate__:
class Connection(obje ct):
* * def __init__(self, host, port):
* * * * self.host = host
* * * * self.port = port
* * * * self.init_sock( )
* * def init_sock(self) :
* * * * self.sock = socket.socket()
* * * * self.sock.conne ct((host, port))
* * * * ... init communication ...
* * def __getstate__(se lf):
* * * * # pickle self as a (host, port) pair
* * * * return self.host, self.port
* * def __setstate__(se lf, state):
* * * * # reinstate self by setting host and port and
* * * * # recreating the socket
* * * * self.host, self.port = state
* * * * self.init_sock( )
I, local, am mystified that you'd want to pickle a socket. *It's a
live connection, which flies on a pocket dollar. *You don't want it on
disk, do you?
If you're running a net buoy through a cluster somewhere, do you want
to drop a server and reconnect? *Is Amazon's EC2 up and running?
Certainly no one was talking on the internet. *Were you?
I don't think you hit anything but banks surfing the web, and the
American dollar is notoriously stuffy. *Pump a wi-fi to a diner,
though, and you're just talking more. *Where's Usenet?

The idea is a pre-fork socket server. *What I want to do is fork off
some child processes from the parent and use IPC to send the
connection object (via socket.accept() ) over a pipe to one of the
preexisting child processes and have said child handle the
transaction. *Think Apache, if you want an example of what I'm trying
to do here. *This alleviates the process startup cost that occurs when
you fork. *If the socket object can't be serialized, is there another
way to go about handling this in python?- Hide quoted text -

- Show quoted text -

That's out of my expertise. You would have to either hack it on a
router you are running (masquerade), or choose a different family of
sockets. For HTTP, you could issue a 'reroute' return. Just multi-
thread your server process.

Jun 27 '08 #11

  • <
  • 1
  • 2

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

Similar topics

1 5101

pickle: maximum recursion depth exceeded

by: Simon Burton |last post by:

Hi, I am pickling big graphs of data and running into this problem: File "/usr/lib/python2.2/pickle.py", line 225, in save f(self, object) File "/usr/lib/python2.2/pickle.py", line 414, in save_list save(element) File "/usr/lib/python2.2/pickle.py", line 219, in save

Python

3 4007

AssertionError in pickle's memoize function

by: Michael Hohn |last post by:

Hi, under python 2.2, the pickle/unpickle sequence incorrectly restores a larger data structure I have. Under Python 2.3, these structures now give an explicit exception from Pickle.memoize(): assert id(obj) not in self.memo I'm shrinking the offending data structure down to find the problem

Python

1774

XML Pickle with PyGraphLib - Problems

by: Mike P. |last post by:

Hi all, I'm working on a simulation (can be considered a game) in Python where I want to be able to dump the simulation state to a file and be able to load it up later. I have used the standard Python pickle module and it works fine pickling/unpickling from files. However, I want to be able to use a third party tool like an XML editor (or...

Python

10 4430

Pickle vs XML for file I/O

by: crystalattice |last post by:

I'm creating an RPG for experience and practice. I've finished a character creation module and I'm trying to figure out how to get the file I/O to work. I've read through the python newsgroup and it appears that shelve probably isn't the best option for various reasons. This lead me to try messing w/ pickle, but I can't figure out how to...

Python

5 92976

Why can't you pickle instancemethods?

by: Chris |last post by:

Why can pickle serialize references to functions, but not methods? Pickling a function serializes the function name, but pickling a staticmethod, classmethod, or instancemethod generates an error. In these cases, pickle knows the instance or class, and the method, so what's the problem? Pickle doesn't serialize code objects, so why can't it...

Python

2 6557

Recursion limit of pickle?

by: Victor Lin |last post by:

Hi, I encounter a problem with pickle. I download a html from: http://www.amazon.com/Magellan-Maestro-4040-Widescreen-Navigator/dp/B000NMKHW6/ref=sr_1_2?ie=UTF8&s=electronics&qid=1202541889&sr=1-2 and parse it with BeautifulSoup. This page is very huge. When I use pickle to dump it, a RuntimeError: maximum recursion depth

Python

3 6087

Problem: Pickle and collections.defaultdict with default_factory set do not work

by: fizilla |last post by:

Hello all! I have the following weird problem and since I am new to Python I somehow cannot figure out an elegant solution. The problem reduces to the following question: How to pickle a collections.defaultdict object that has set the default_factory property? For Example (from the IDLE console): >>> words =...

Python

2 4499

Memory error while saving dictionary of size 65000X50 using pickle

by: Nagu |last post by:

I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine later if this is a problem due to limited resources (memory) on the machine (it is 32 bit machine Win XP, with 4GB RAM). Here is the detail...

Python

1725

Memory error while saving dictionary using pickle

by: Nagu |last post by:

I am trying to save a dictionary of size 65000X50 to a local file and I get the memory error problem. How do I go about resolving this? Is there way to partition the pickle object and combine later if this is a problem due to limited resources (memory) on the machine (it is 32 bit machine Win XP, with 4GB RAM). Please advice. Thank you,

Python

1 6335

Pickle problem : Can't pickle 'SRE_Match' object:

by: IceMan85 |last post by:

Hi to all, I have spent the whole morning trying, with no success to pickle an object that I have created. The error that I get is : Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at 0x2a969c0ad0> the complete stack is the following : Traceback (most recent call last): File "manager.py", line 305, in ? commandLineExec...

Python

8058

Problem With Comparison Operator <=> in G++

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. ...

C / C++

8241

Maximizing Business Potential: The Nexus of Website Design and Digital Marketing

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...

Online Marketing

1 7820

The easy way to turn off automatic updates for Windows 10/11

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...

Windows Server

6456

AI Job Threat for Devs

by: agi2029 |last post by:

Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...

Career Advice

1 5624

Access Europe - Using VBA to create a class based on a table - Wed 1 May

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...

Microsoft Access / VBA

5301

Couldn’t get equations in html when convert word .docx file to html file in C#.

by: conductexam |last post by:

I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...

C# / C Sharp

3742

Trying to create a lan-to-lan vpn between two differents networks

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...

Networking - Hardware / Configuration

3753

Windows Forms - .Net 8.0

by: adsilva |last post by:

A Windows Forms form does not have the event Unload, like VB6. What one acts like?

Visual Basic .NET

1 2249

transfer the data from one system to another through ip address

by: 6302768590 |last post by:

Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

C# / C Sharp

pickle problem | Bytes (2024)
Top Articles
Latest Posts
Article information

Author: Virgilio Hermann JD

Last Updated:

Views: 6587

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Virgilio Hermann JD

Birthday: 1997-12-21

Address: 6946 Schoen Cove, Sipesshire, MO 55944

Phone: +3763365785260

Job: Accounting Engineer

Hobby: Web surfing, Rafting, Dowsing, Stand-up comedy, Ghost hunting, Swimming, Amateur radio

Introduction: My name is Virgilio Hermann JD, I am a fine, gifted, beautiful, encouraging, kind, talented, zealous person who loves writing and wants to share my knowledge and understanding with you.