[ZODB-Dev] URGENT: ZODB down - Important Software Application at CERN

Marius Gedminas marius at gedmin.as
Wed May 27 08:54:24 EDT 2009


On Wed, May 27, 2009 at 12:17:36PM +0200, Hanno Schlichting wrote:
> Chris Withers wrote:
> > Hanno Schlichting wrote:
> >> They are incredibly expensive to unpickle since all
> >> the DWIM magic in their __init__ get called each time, though.
> > 
> > How come? Unpickling doesn't call __init__ and I don't see why the DWIM 
> > magic would be needed anyway, since everything has already been parsed.
> 
> How would a new instance of a class be constructed without calling the
> init or new?

You're cleverly changing the question ;-)

*Most* objects are unpickled by calling __new__ followed by
__setstate__, but without calling __init__.  Chris is therefore
understandably surprised.

Old-style classes that define __getinitargs__ will get their __init__
called during unpickling, though, and DateTime is such a class.

You could also cause the __init__ to be called by defining __reduce__
or __reduce_ex__ appropriately.  This is all described in great detail
at http://python.org/doc/current/library/pickle.html#pickle-protocol

>Look at the _instantiate method in pickle.py, when it does:
> 
> value = klass(*args)
> 
> What happens on unpickling is that a new DateTime instance representing
> "just now" is generated and then that instance is updated with the
> values from the pickle.

Marius Gedminas
-- 
Every nonempty totally-disconnected perfect compact metric space is
homeomorphic to the Cantor set.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zodb-dev/attachments/20090527/7fe4c406/attachment.bin 


More information about the ZODB-Dev mailing list