pickle problem
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Thu May 8 23:54:44 EDT 2008
On Thu, 08 May 2008 23:35:04 +0200, Hrvoje Niksic wrote:
> Marc 'BlackJack' Rintsch <bj_666 at 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__:
When does it make sense!?
> class Connection(object):
> def __init__(self, host, port):
> self.host = host
> self.port = port
> self.init_sock()
>
> def init_sock(self):
> self.sock = socket.socket()
> self.sock.connect((host, port))
> ... init communication ...
But if you unpickle it while the original connection is still open it
can't connect. If it's not open anymore, there's no one answering at
host/port anymore or some program that has no idea what this connection
is all about.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list