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.


    atexit module not working

    Pythonista
    6
    6
    4560
    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.
    • Larry_Mondello
      Larry_Mondello last edited by

      Even the simple examples in the Standard Library docs for the atexit module do not seem to work in Pythonista.

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        It's not possible to make this work on iOS. The interpreter has to run in the same process as the app, so it never terminates...

        MTcoder 1 Reply Last reply Reply Quote 0
        • MTcoder
          MTcoder @omz last edited by

          @omz atexit seems to work fine in Pythonista 3 -- is it true? Has this issue been solved?

          1 Reply Last reply Reply Quote 1
          • JonB
            JonB last edited by

            atexit was added in pythonista 2.1/3.0, although it only is called when sys.exit is called, not when pythonista closes, if memory serves

            1 Reply Last reply Reply Quote 0
            • Webmaster4o
              Webmaster4o last edited by

              @MTcoder Now the python interpreter runs in a separate process, that's why

              1 Reply Last reply Reply Quote 0
              • towerofnix
                towerofnix last edited by towerofnix

                I'm on Pythonista 3 and atexit.register on its own doesn't quite work - running sys.exit will call the registered atexit function but forcibly terminating the program (via the stop button) doesn't do that.

                Using a try..finally like this, worked, though:

                @atexit.register
                def _exitcb():
                  print('Exit')
                
                try:
                  # Do stuff
                finally:
                  exit()
                

                I'm not sure if that's how it would normally work on a computer running Python but that's just a tiny tidbit of hopefully helpful information for anyone coming across this issue.

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