Unbound names in __del__

Torsten Bronger bronger at physik.rwth-aachen.de
Fri Jun 17 03:17:17 EDT 2005


Hallöchen!

"Terry Reedy" <tjreedy at udel.edu> writes:

> "Torsten Bronger" <bronger at physik.rwth-aachen.de> wrote:
>
>> Is there a way to detect whether the program is being terminated?
>
> See atexit module to register cleanup functions that run *before*
> the interpreter starts haphazardly deleting stuff.

So I could register a function that sets a global variable called
"shutdown_has_begun" to "True".  Then I say

def __del__(self):
    if shutdown_has_begun: return
    ...

Alternatively, I could enclose every __del__ contents block with a
"try" whithout catching anything, just to suppress the error
messages.

However, all of this is not pretty pythonic in my opinion.  Is it
that exotic to want to call functions from within __del__?

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus



More information about the Python-list mailing list