I have 12 programs which i intend to run simultaneously. Is there any way i run all of them via one single program which when built runs the 12 programs?
I am using sublime and the programs are python.
I have 12 programs which i intend to run simultaneously. Is there any way i run all of them via one single program which when built runs the 12 programs?
I am using sublime and the programs are python.
If you just want to execute the programs one by one in a batch, you can do it in a bash script. Assuming they are executables in the same folder, you can have an .sh file with the following contents:
#!/bin/bash
python ./my_app1.py &
python ./my_app2.py &
python ./my_app3.py
If the scripts themselves have the #!/usr/bin/env python at the top to identify the interpreter, you can do chmod +x on them, and turn your runner.sh file into:
#!/bin/bash
./my_app1.py &
./my_app2.py &
./my_app3.py
On the other hand, if you want to do this from a python script, you can use:
import subprocess
import os
scripts_to_run = ['my_app1.py', 'my_app2.py', 'my_app3.py']
for s in scripts_to_run:
subprocess.Popen([os.path.join(os.getcwd(), s)])
Note 1: don't forget to include the #!/usr/bin/env python in every script on the first line.
Note 2: it is important to use subprocess.Popen() instead subprocess.call() because the latter is a blocking function that will wait for the application to finish before proceeding. With subproces.Popen() you get the concurrent execution.
stdout, stderr to PIPE unless you read from them eventually. It may lead to a deadlock if any of the scripts generates enough output. Don't introduce data dependant bugs; it is worse even if your code just failed immediately (at least it would shows that there is a problem).