Ian Kelly wrote:

> On Wed, Mar 9, 2016 at 2:14 AM, Veek. M <vek.m1...@gmail.com> wrote:
>> what i wanted to know was, x = Client('192.168.0.1') will create an
>> object 'x' with the IP inside it. When I do:
>> pickle.dump(x)
>> pickle doesn't know where in the object the IP is, so he'll call
>> __getstate__ and expect the return value to be the IP, right?
> 
> pickle doesn't care what the return value is, other than it needs to
> be something picklable. I suggest returning a dict containing the IP
> address, to make it easier to add additional state later if needed.
> 
> That said, I wouldn't pickle a TCP client in the first place. You may
> be able to restore the client state, but you can't easily restore any
> server state, which could easily lead to mismatching network states.
> Also, what do you think should happen if the connection fails while
> unpickling?
> 
Actually that's just what I was asking: when __getstate__ is called, 
it's upto getstate to return the object to be pickled - it could be an 
IP passed in by the user or pretty much anything 'hello world' even.

Anyway, i think the point of that example (from the book) is that he's 
not saving TCP state info. Instead he provides a seamless iface so the 
user won't even realize the connection had failed (meaning he'll reopen 
the link using the pickled IP and pretend the link never went down).

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to