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.


    Wishlist: Reset interpreter

    Pythonista
    4
    7
    4261
    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.
    • georg.viehoever
      georg.viehoever last edited by

      I Would like to have a Button that Resets the Python Interpreter into the State that it has when the Application is launched . Use Case: when developing a Module, it is difficult to convince Python to reload changed module sources. Reset Would make this easy and Would also be a way to get Pythonista into a well defined State in Case of Other Problems. Currently, this requiries killing pythonista from iOS, which is a bit annoying.
      Georg

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

        import my_module ; reload(my_module)  # Pythonista workaround
        
        1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 last edited by

          Yes, I use the reload all the time. Under 1.5 , I found even with the reload(module), I often had to run twice before the changes of the imported module would take effect. Which is fine. Better than quitting Pythonista. Haven't tried it in 1.6 yet

          1 Reply Last reply Reply Quote 0
          • georg.viehoever
            georg.viehoever last edited by

            @ccc I know! But a reset is even better... It helps with monkey-patched methods, misconfigured globals, and a lot more circumstances that can make a running Python interpreter behave weird.
            Georg

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

              This is going to sound stupid, but is there anyway to have python to run a pre and post script when executing a script? Globally, I mean.
              I am guessing not, but if it was possible could possibly provide a solution here as well to other issues also.

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

                i wonder if it would be possible to pickle sys.modules in a clean session, then load it again when you want to reset. Alternatively, store a list of modules that are loaded at start, and then resetting the interpreter would consist of deleting any modules that don not belong, and maybe reloading any modules which do.

                for m in sys.modules.keys() if not m in oldmodules:
                   del sys.modules(m)
                
                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB @Phuket2 last edited by

                  @Phuket2 you can create your own action menu item which does what you say. I have an action menu to run a script in the same interpreter ( without clearing globals) because i find that easier for debugging. You could add some lines before/after the execfile.

                  # execute script in editor, in current interpreter session without clearing globals
                  import editor,os
                  file=editor.get_path()
                  
                  os.chdir(os.path.dirname(file))
                  execfile(file)
                  
                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post
                  Powered by NodeBB Forums | Contributors