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 run two or more program?

    Pythonista
    2
    5
    3723
    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.
    • wolf71
      wolf71 last edited by

      Just like stash, it's can run N time same time.

      Who can write a deom to show how to run two program same?

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

        Stash uses Threads, plus much of stash is ui based, which allows callbacks to run seperate from the console.

        As a simple example: this code will simply babble on, while you can do other work. set abort=True to cancel.

        import threading
        import time
        abort=False
        def ping():
        	while not abort:
        		print('I am thread number 1')
        		time.sleep(5)
        def pong():
        	while not abort:
        		print('I am thread number 2')
        		time.sleep(5)
        
        threading.Thread(target=ping).start()
        threading.Thread(target=pong).start()
        
        
        1 Reply Last reply Reply Quote 1
        • wolf71
          wolf71 last edited by

          Thanks.
          stash uses ui based ,not just threads.
          run this demo,need using stop to stop program. and you cant't running other program.

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

            The examle does not prevent you from running another program -- notice the play button is immediately available again.... though in this example i did not retain the required globals so pressing play in another script clears a variable needed by the threads.

            There are a few aspects to your question, i think:

            1. How to show two ui's. you use present('panel') to show the ui in a tab
            2. to prevent global clearing of custom imported modules, there are a few strategies...the easiest is that any imports should be built ins or based in site-packages, as these will not be cleared. Note that means when you are developing, you should develop outside of site-packages or your module does not get reloaded when you make changes. or you would use
            import mymodule
            reload(mymodule)
            

            to ensure your changes get reflected. you can also modify the __file__ attribute so it does not start with './' or the abspath of the documents directory (for instance, set it to the abspath, but replace Documents with a '/./Documents', that currently is enough to fool the preflight script.)

            3) global variables, should live inside such a saved module.  for instance, stash uses a launcher script where it imports a module, then runs main on the imported module, so any globals are only global within the module, and not truly the global scope.  this can make it harder to debug.  you can also import and add any globals you want to save to the pythonista_startup module.  
            
            import pythonista_startup
            pythonista_startup.myglobalvariable = myglobalvariable
            

            You can also prepend two underscores, which lets them survive the global clearing.
            Of course, with any of these approaches, if you run the same script twice, you have to kake sure you don.'t delete your saved globals, otherwise your ui's will be looking for variables that don't exist

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

              Thanks.

              Just using a simply method.

              1. start 2 or 3 stash.
              2. At stash , using python xxx.py to run the program.

              so you can run more then one program same time.

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