How to run two or more program?
Just like stash, it's can run N time same time.
Who can write a deom to show how to run two program same?
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()
stash uses ui based ,not just threads.
run this demo,need using stop to stop program. and you cant't running other program.
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:
- How to show two ui's. you use present('panel') to show the ui in a tab
- 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
Just using a simply method.
- start 2 or 3 stash.
- At stash , using python xxx.py to run the program.
so you can run more then one program same time.