This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: __del__: Type is cleared before instances
Type: behavior Stage: test needed
Components: Interpreter Core Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, arigo, arunarunarun, benjamin.peterson
Priority: normal Keywords:

Created on 2006-06-28 07:41 by arunarunarun, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py arunarunarun, 2006-06-28 07:43 Script to demonstrate the problem
Messages (4)
msg28960 - (view) Author: Arun (arunarunarun) Date: 2006-06-28 07:41
[Python n00b alert]

I'm trying this little script, and I see an exception like:

Exception exceptions.AttributeError: "'NoneType' object
has no attribute 'refcount'" in <bound method
Shape.__del__ of Line> ignored

If I change the variable name 's1' to something like
's4', I don't see this exception. Also, if I manually
delete the object before the script ends, the exception
does not occur.

Seems that class Shape is destroyed before all it's
objects are destroyed. Is this acceptable?
msg28961 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2006-06-29 21:29
Logged In: YES 
user_id=4771

It is not the type object that is cleared, it is the global
names of the module.  They are replaced with None when the
interpreter shuts down, which is why the expression
'Shape.refcount' find None under the name 'Shape'.  It's an
obscure leftover for historical reasons.  I'm not sure why
the problem somes bites and sometimes not.  A workaround is
to avoid reading globals from __del__() methods; e.g. use
self.__class__.refcount instead of Shape.refcount...

(This of course doesn't excuse the fact that this is a
long-standing bug.)
msg84514 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-03-30 05:56
Confirmed on trunk and py3k. Has this passed the the won't-fix threshold?
msg84539 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-30 12:15
No, but I believe this is addressed in some other bugs like #812369.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43567
2009-03-30 12:15:00benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg84539

resolution: duplicate
2009-03-30 05:56:52ajaksu2setversions: + Python 2.6, Python 3.0, - Python 2.4
nosy: + ajaksu2

messages: + msg84514

type: behavior
stage: test needed
2006-06-28 07:41:12arunarunaruncreate