How to un-register/un-observe cleanly when script exits?
shinyformica last edited by
For those of us who are extensively making use of the objective-c bridge to observe notifications and key/value changes, what is the right pattern to use for disconnecting from those things when the script exits?
I have this pretty complex UI at this point, and it makes use of quite a few different notification center observers, and a few key-value observers as well, from many different ui.View subclasses, and they all need to be disconnected when the UI, which is presented full-screen, is closed. Otherwise, tracebacks will occur when the callbacks for objects which have now been cleared from the globals, get called after the script has exited.
So what are people doing? Are you manually keeping track of everything and then going through it all when the main UI
will_close()is called? Unfortunately, it appears that my individual ui.View classes don't get their
__del__()method called when the main ui.View they live under is closed, so I can't just do the unregistering there. Is there a nice, clean way that individual subviews can know when the main view has been closed, but without having to have some big "loop over all subviews and tell them to clean up", which is what I'd have to do now?