rectangletangle rectangletangle - 1 month ago 22
Python Question

Telling if an Instance has been Destroyed

I have a list of instances of objects (wxPython widgets). I'd like to be able to tell if an instance within my list has been destroyed. How would one go about this?

Answer

Assuming wxPython is playing by the rules and by "destroyed" you mean "is no longer referenced", then the weakref module in the standard library should let you do what you want (specifically, you can register a callback when creating a weak reference that is invoked just before the target of the weak reference is destroyed).

If wxPython isn't playing by the rules, or has disabled weak referencing for its objects, you may be out of luck.