omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    How to un-register/un-observe cleanly when script exits?

    Pythonista
    notifications objc observe
    1
    1
    1102
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shinyformica
      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?

      1 Reply Last reply Reply Quote 1
      • First post
        Last post
      Powered by NodeBB Forums | Contributors