[ZODB-Dev] weakref and Persistent

Christian Reis kiko at async.com.br
Tue Apr 22 21:16:30 EDT 2003


Hi there,

We've been using weakref to make our UI library cache access to values in
domain objects. However, when I try to test weakref.ref() on Persistent
instances, I realize it doesn't work as I hoped:

    >>> import weakref
    >>> from ZODB import Persistence
    >>> class X(Persistence.Persistent):
    ...  pass
    ... 
    >>> x = X()
    >>> y = weakref.ref(x)
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      TypeError: 'X' objects are not weakly referencable

In the Python doc it says "Extension types can easily be made to support
weak references"; does this include ZODB.Persistence.Persistent (and
would a patch be appreciated), or is it non-trivial and that's why it's
not supported?

Toby once wrote that the semantics were murky [1]; anybody see a
workaround or would like to drop the hammer on this one?

[1] http://mail.zope.org/pipermail/zodb-dev/2002-January/002228.html

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL



More information about the ZODB-Dev mailing list