I have some small python 2.6 scripts built....
Now, I would like run them as seperate processes within a python shell. Each as a seperate process. If one fails to run maybe with its timer, I would like others to continue without killing all scripts.
Should I do this as singleton gui's or combine them into bigger launch pad. My perference would be launch pad type gui....Any ideas?
Its seems that launching scripts out of SciTE, works ok.
Check joblaunch, a shell tool I made for executing interdependent jobs in parallel locally. It has more options.
Related
I need to run at the same time this two instruction within a python script.
GPIO.output(17,True)
os.system('gphoto2 --capture-image-and-download')
it is important to start them simultaneously.
How can I do that?
As you know - Python is single - threaded. But you can get around this with several ways:
Run multiple Python threads. For example: split your script for to scripts and run them with to different python process simultaneously, like python script1.py in one terminal window and python script2.py in second terminal window.
Use multi-thread module which allows run Python functions in different threads. You can easily find a lot of quick tutorials or just read official docs above.
Also Python allows use multi-process too. The idea is similar like splitting your script on different scripts.
I have 2 py scripts that are sending commands via ethernet to turn on/off logic levels in various electronic components. The GUI's themselves are a very simple interface, however, I am not a python guy. I am able to open up one GUI with Spyder, run the script and control the system just fine, but I need to run 2 scripts simultaneously. Both scripts are similar in nature and operation. Is there a way to run both in Spyder? Or one from two different IDE's? Thank you.
I'm not sure if i fully understand your use case but if the scripts don't take long to execute and when you say run simultaneously you mean at very nearly the same time then you could just write a shell script to execute them consecutively with some timer function if running on a regular schedule. Might need more details to know if that's appropriate. If you need them to run in parallel then that's a different matter.
You'll just be creating a file.sh with something along the lines of:
python script1.py
python script2.py
inside and some logic to run it on whatever schedule you desire
Do they have to run in Spyder? If they are just python scripts you should not need an IDE, just use two command line terminals and run script1.py in one, and script2.py in the other
I'm not sure if what I'm wanting to do is possible, but:
I have a python script (lets call it PY) that calls a batch script to start a tool in terminal mode (lets call it A). This tool gets passed a starting script (tcl script) that sets up its environment and launches a second tool (lets call it B). The two tools communicate over a TCP connection locally.
My question is, with these two programs running (A and B), can I switch back to the python script to run commands in either A or B's TCL interface?
The scripts look sort of like this:
#python PY
def ReadConigAndSetup():
#read some data
...
#run bat
subprocess.run("./some_bat.bat some_data_args")
#bat start program A and pass it a startup script
some_program_A -mode tcl -source ./some_source.tcl
#tcl some_source.tcl
setup environment
open TCP port
start program B
#program B setup tcl
some more setup
after program B has run I'd like to be able to run more commands in program B from python as parsing some of the config files is much easier in the python environment.
The answer is “it depends on the details”.
There's no reason in principle why the program being called can't work fine this way, provided the subprocess relinquishes control back (which it might or might not), but launching complex programs via a BAT file is adding an extra layer of complexity so you might want to think about whether you can simplify a bit there.
If the program running the Tcl code doesn't terminate, things get trickier. This is an area where the details are critical; Tcl code can be written to loop indefinitely — it's a programming language so of course it can be told to be annoying if you insist — and the program being controlled could also decide to loop indefinitely of its own accord, which can happen particularly with GUI applications as the looping is where the user is interacting with the GUI. On Windows, many GUI applications run disconnected from the terminal (whether they do this is a compile-time option) and waiting for them to finish can be quite annoying.
It's possible to run multiple subprocesses at once using subprocess.Popen. Be very careful if you do this. It's possible to get into deadlocks (though that depends a lot on what the subprocesses are doing). It's probably easier to just launch each subprocess from its own thread… but then you're dealing with threads and that's also complicated.
I'm trying to launch an exe in Python to capture data from an eyetracker, I'm using Popen and it's able to launch fine. However I'm simultaneously running a psychovisual experiment using psychopy. I'm not sure how to use Popen to synchronise the launch of both processes, I know that this has something to do with threading - and a found a useful blog on the subject here (http://zulko.github.io/blog/2013/09/19/a-basic-example-of-threads-synchronization-in-python/) however, I'm not sure how to translate this to my case as I'm new to Python. Additionally, closing the exe after my experiment is over is something that I'm not sure how to actually do
my code is roughly as follows
tracker = Popen("..\API\samples\Debug\precision_accuracy.exe".split(),stdout = PIPE) # calling exe
for i in range(stuff):
do my experiment
I'm using windows, any help at all would be massively appreciated
I need to create a python script that monitors another python script, specifically, some variables from it. I was thinking of creating an independent thread in the "observer script" that does this. This thread must run until the "executer script" finishes. Maybe all of this can be done inside one big script (observer+executer), I really do not know at the moment.
Is it possible at all to do this with python in windows?