Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104454
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 |
| Date | 2016-03-09 14:28 -0700 |
| Message-ID | <mailman.97.1457558969.15725.python-list@python.org> (permalink) |
| References | <nbjt3b$69k$1@dont-email.me> <mailman.71.1457511067.15725.python-list@python.org> <nbopc0$3eh$1@dont-email.me> |
On Wed, Mar 9, 2016 at 2:14 AM, Veek. M <vek.m1234@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?
> Similarly, whilst unpickling, __setstate__ will be called in a manner
> similar to this:
> x.__setstate__(self, unpickledIP)
>
> __setstate__ can then populate 'x' by doing
> self.x = str(unpickledIP)
>
> the type info is not lost during pickling is it, therefore 'str' is not
> required is it?
Correct.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 "Veek. M" <vek.m1234@gmail.com> - 2016-03-07 18:17 +0530
Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 dieter <dieter@handshake.de> - 2016-03-09 09:10 +0100
Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 "Veek. M" <vek.m1234@gmail.com> - 2016-03-09 14:44 +0530
Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-09 14:28 -0700
Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 "Veek. M" <vek.m1234@gmail.com> - 2016-03-10 06:31 +0530
Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172 dieter <dieter@handshake.de> - 2016-03-10 09:06 +0100
csiph-web