[ZODB-Dev] weakref and Persistent
Phillip J. Eby
pje at telecommunity.com
Wed Apr 23 17:51:46 EDT 2003
At 04:38 PM 4/23/03 -0400, Tim Peters wrote:
>[Phillip J. Eby]
> > ...
> > So, I guess this should be a good indication that persistent objects will
> > be potentially weakref-able under ZODB4. (I say potentially, because
> > Persistent subclasses that define '__slots__' and don't inherit from an
> > already weakref-able base class, will not be weakref-able.)
>
>I'm not sure exactly what you have in mind there, but if you have a specific
>example, try adding the string '__weakrefs__' to the class's __slots__.
>That's usually all it takes (Python needs an attr named __weakrefs__ to
>implement weak references, and if you use __slots__ then Python can't create
>any new attrs by magic; but you can create the __weakrefs__ slot yourself
>then).
I was just trying to point out to the original poster that just because
ZODB4 supports weak references in general, it's possible that he might
encounter a unreferenceable persistent class written by a third party.
Side note: I'm already all too painfully aware of how the slots machinery
for weakref pointers works; I wrote the code in ZODB4 that swaps the
weakref and dict pointers in newly created types to avoid Python flipping
out when you use multiple inheritance with Persistence under Python
2.2. To do that I had to learn all sorts of legislation-and-sausage (i.e.
things best not watched while they're being made) about how slots are laid
out and __base__ is chosen. :)
More information about the ZODB-Dev
mailing list