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.


    restart interactive interpreter?

    Pythonista
    3
    6
    4362
    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.
    • lsloan117
      lsloan117 last edited by

      How does one restart the Python interpreter in the interactive panel?

      I tried sys.exit(), which I thought would make a new one start once the current one had exited. However, it just printed "EXIT (0)" and continued running.

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

        Shutting down Pythonista:<br>
        http://omz-software.com/pythonista/forums/discussion/888/quit-the-script/p1

        Keeping your Pythonista script from going to sleep:<br>
        http://omz-software.com/pythonista/forums/discussion/comment/1293#Comment_1293

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

          Thanks for the suggestion. It may help, but it's still rather hack-ish. I wish @omz would change Pythonista to let the Python interpreter exit as it normally would, either from a crash, a call for sys.exit(), or other appropriate method call. Then Pythonista could either start a new interpreter automatically or prompt the user to tap a button to start one.

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

            So, just to follow-up...

            Through some experimentation with os.getpid(), I learned that the interactive interpreter and all of my programs are running from the same process. I was surprised by this because I expected a new interpreter to start each time a program is run and it would terminate when the program does. Apparently, the way @omz implemented Pythonista, the Python interpreter isn't a subprocess, it's part of the main one and it's reset whenever a program is run. That same interpreter (or a parallel one?) handles the interactive prompt, but there's no way to reset it.

            It also appears that sys.exit() is trapped to print that EXIT (0) message. IMHO, I think the trap should reset the interpreter, if not start a new one.

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

              @lsloan I'd love to run the interpreter in a sub-process, but that's not possible on iOS (Apple's policy).

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

                I understand, @omz. You need to play by their rules.

                Could you describe what Pythonista does whenever a program is run? It seems to clear the environment first, because variables don't retain their values from one run to the next. If calls to sys.exit() are trapped, could it also clear the environment then?

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