rectangletangle rectangletangle - 5 months ago 60
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?


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.