any way to know when the program is exiting?

Gordon McMillan gmcm at hypernet.com
Thu Jul 29 07:57:15 EDT 1999


Ovidiu Predescu wrote:
> 
> I was wondering if there is any way in a __del__ method to know when
> it's invoked on the way out, as a result of the program going away?
> 
> I have a __del__ method of a class that sends a message to a global
> variable. It happens that on the way out, that value in that
> variable is destroyed before the __del__ methods of my instances are
> invoked. The result is that I have a bogus value that doesn't
> respond to the usual methods anymore. How can I prevent sending
> messages to that object?

You rely on just what you described. Globals are nuked first, but 
they don't end up with random bogus values, they are set to the one 
and only None object.

  def __del__(self):
    if globalvar is None:
      # we're on the way out...

- Gordon




More information about the Python-list mailing list