[Python-Dev] patch-finalizer vs Zope3
Tim Peters
tim.peters at gmail.com
Sun Nov 7 06:07:37 CET 2004
[Tim]
...
> surrogates = {Default.weakref(): default, Null.weakref(): null}
> def _remove(k):
> try:
> del surrogates[k]
> except KeyError:
> pass
FYI, if I fiddle that part to use the same kind of odd spelling
Python's weak dicts stumbled into for other reasons:
surrogates = {Default.weakref(): default, Null.weakref(): null}
self._surrogates = surrogates # new
def _remove(k, selfref=weakref.ref(self)): # changed
self = selfref() # new
if self is not None: # new
try:
del self._surrogates[k] # changed
except KeyError:
pass
then the Zope3 unit tests don't leave anything in gc.garbage under
2.4b2 + patch-finalizer. A spattering of tests fail (2 failures + 3
errors), though, due to new
TypeError: can't pickle weakref objects
exceptions.
Note that in this case the callbacks get invoked but are impotent:
self isn't strongly reachable from the callbacks, so self is left in
the unreachable set, and so the `selfref` weakref (which does not have
a callback) gets cleared before gc starts breaking cycles: all the
callbacks see selfref() return None.
More information about the Python-Dev
mailing list