[ZODB-Dev] How do you "wake up" sleepy persistent objects?
Jim Fulton
jim@zope.com
Thu, 11 Oct 2001 18:37:35 -0400
Let me try to summarize.
First, you usually don't need to wake up ghosts. Why would
anyone want to wake up a ghost? I can see doing it
during debugging, but not otherwise.
In general, messing with an objects __dict__ is impolite. :)
You really shouldn't count on getting anything from a __dict__.
The only time to mess with a __dict__ is when you actually want
to defeat the normal persistence machinery. We recently used this
hack^H^H^H^Htechnique in a DTML optimization.
In Python 2.2, __dict__ will be a far less important than
it is now in standard Python. It will be much more bad form to
access a __dict__ than it is in Python now.
I imagine that dir does some attribute access that causes
persistent objects to be activated.
I don't realloy consider the fact that you can't count on __dict__
to be a gitcha in ZODB. It is a little unfortunate that dir doesn't
always do the right thing.
Jim
Chris McDonough wrote:
>
> > When a persistent object is in the ghost state, it appears that the
> results
> > of dir(object) are not the same as when the object is in some other state.
> > It also appears that doing dir(object) wakes up the object (albeit, after
> > the fact) so that a subsequent dir(object) returns the results that you
> > would expect.
>
> This is right. This can definitely be disconcerting, but usually this only
> bites me when I'm in the debugger for whatever reason.
>
> > Is my description correct? Is this expected/known behavior? Is this
> behavior
> > documented anywhere? Are there any other "gotchas" I need to be aware of
> > related to this? Is there a "correct" way to "wake up" a ghost?
>
> I believe that another "gotcha" (if you want to call it this), is that
> examining the __class__ attribute of a ghosted object does *not* wake the
> object up. This can actually be handy.
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list - ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev
--
Jim Fulton mailto:jim@zope.com Python Powered!
CTO (888) 344-4332 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org