I ‘m new with the Python world. I have four Python Script, and now during the testing phase, i have to run each of one from differenti console istances. My question is: is possible to create an unique script Python, and from it execute at the same time, the 4 scripts. I’am working with a publisher/subscriber architetture, so i have one publisher and three sbuscriber.
2 Answers
Personally, I wouldn't run them from python. Create a batch file (windows) or a bash script(linux) and run all four of them as a background process so that they don't have to wait for each other to complete
2 Comments
The_blade
Thanks, can suggest me some examples?
Arran Duff
on a linux system you would create a file called something like run_all.sh and add the following lines to it
nohup python script_1.py & nohup python script_2.py & nohup python script_3.py & nohup python script_4.py & Then run chmod +x run_all.sh ./run_all.shIn python you can try to use something like this:
import os
# list with the name of your scripts
scripts=["script_1.py", "script_2.py","script_3.py"]
for i in range (len(scripts)):
print "Executing ", scripts[i]
# string with script parameters
# in this case they are identical for everyone
script_parameters="-p parameters"
# build the command as if you typed it in the terminal
#
my_command = "python"+" "+scripts[i]+" "+script_parameters
print my_command
# run your command on the operating system
os.system(my_command)
I do not know if this is what you were looking for, but I hope you find it useful