Antoine Pitrou added the comment:

weakrefs are traditionally cleared by the cyclic GC before calling any __del__ 
method. This used to be mandatory to eschew situations where a weakref callback 
could see cleared objects, but produces the side effect that __del__ methods 
can see dead weakrefs. This is also true pre-3.4, by the way, but perhaps the 
OP's __del__ wasn't called at all (if it was part of the cycle, the object 
would end up in gc.garbage instead)?

We could perhaps reverse the order, but then weakref callbacks may see 
__del__'ed objects. Hard to say which one is better, and keeping the 
traditional behaviour means less compatibility hassles.

Some of this is discussed in Modules/gc_weakref.txt.

In general, __del__ methods may see strange errors. For example, at interpreter 
shutdown, your __del__ method can be called while some modules have started 
unloading. Python 3.4 definitely tries to improve on all this, but there's no 
perfect solution, and some of the improvements might also backfire in some rare 
cases :-)

----------
nosy: +tim.peters
versions: +Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23841>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to