Re: a Python bug in processing __del__ method ??

From: Fredrik Lundh (fredrik_at_pythonware.com)
Date: 01/31/05


To: python-list@python.org
Date: Mon, 31 Jan 2005 08:02:11 +0100

Baoqiu Cui wrote:

> The error returned is this:
>
> $ python bug.py
> Exception exceptions.AttributeError: "'NoneType' object has no
> attribute 'population'" in <bound method Person.__del__ of
> <__main__.Person instance at 0xa0c9fec>> ignored
>
> However, if I rename variable name 'peter' to something like 'peter1'
> or 'david', the error is gone. Looks to me the
> error only happens to variable name 'peter'.
>
> Does anyone know what is wrong? Is this a bug only on Cygwin?

it is not a bug, and the documentation has the answer:

    language reference -> index -> __del__

    http://docs.python.org/ref/customization.html#l2h-175

    Warning: Due to the precarious circumstances under which __del__()
    methods are invoked, exceptions that occur during their execution are
    ignored, and a warning is printed to sys.stderr instead. Also, when
    __del__() is invoked in response to a module being deleted (e.g.,
    when execution of the program is done), other globals referenced by
    the __del__() method may already have been deleted. For this reason,
    __del__() methods should do the absolute minimum needed to
    maintain external invariants.

if you absolutely need to have reliable access to globals, you need to make
sure they're available as instance variables, or are bound in some other way.

</F>



Relevant Pages

  • Re: a Python bug in processing __del__ method ??
    ... >>or 'david', the error is gone. ... >>error only happens to variable name 'peter'. ... Is this a bug only on Cygwin? ... exceptions that occur during their execution are ...
    (comp.lang.python)
  • Re: yesterday, it steers a composer too careful after her expected world
    ... Whoever wholly secure until vertical psychological schedules. ... approval in spite of the execution is too generous for Ramzi to ... Peter never boils until Ayub robs the competitive ... Charlene called the coherent weddings in charge of acceptable ...
    (sci.crypt)
  • Re: Peter update
    ... "uh oh" - he was lethargic, slightly lame behind and his temperature was ... Luckily, vet showed up right on time, pumped him full of cortisone, ... into the horse's skin when the bug bites. ... twice a day will relieve a great deal of misery for Peter, ...
    (rec.equestrian)
  • Addendum Re: Internet Explorer Pop-Up OBJECT Tag Bug
    ... adding an addendum about the bug which Dave ... able to control the execution of software). ... Download unsigned Activex controls - Disable ... Safe for Scripting - Disable ...
    (Bugtraq)
  • Re: Switch statement help
    ... Also remember a very annoying cross-language bug in switch ... It's like having to put break after each function body so execution ... function bar() { ... maybe to have a flag to "continue" execution of underlaying branches - ...
    (comp.lang.javascript)