pickle problem

castironpi at gmail.com castironpi at gmail.com
Thu May 8 01:27:43 EDT 2008


On May 7, 11:02 pm, krustymon... at gmail.com wrote:
> 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

The group currently holds that pickling socket objects is non-optimal
to the ends of making money.  We can tell you good ways to accomplish
what you set out to do all the same.  I find it educational; that's
fine in my book.  Part of the resistence comes from a resistence to
monarchy.  The bottleneck is the starting of a second Python process.

There are a number of objects which can't be pickled, though.  If you
can objectively prioritize the next step in pickling sockets, you may
find out sooner when it will come in to Python.  But that's the hard
part; speaker recommends against.

We accept your idea is to get a process around the socket barrier.
Can you close the server in Part N, hear the connection in Part N+1,
spawn a new server in N+2, and handle the first one in N+3?  Is it
suitable to your minds?



More information about the Python-list mailing list