def monitor_object_cleanup(o, fn=lambda *args: None): init() # Required so that GetListOfCleanups().RecursiveRemove() is called. o.SetBit(o.kMustCleanup) args = fn, type(o).__name__, o.GetName(), o.GetTitle(), repr(o) MONITORED[objectproxy_realaddress(o)] = args
def on_cleanup(tobject): # Note, when we arrive here, tobject is in its ~TObject, and hence the # subclass part of the object doesn't exist, in some sense. Hence why we # store information about the object on the MONITORED dict. addr = objectproxy_realaddress(tobject) if addr in MONITORED: args = MONITORED[addr] fn, args = args[0], args[1:] fn(tobject, *args) del MONITORED[addr]