The_blade
The_blade

Reputation: 31

How to run simultaneously four Python scripts from another scripts

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.

Upvotes: 0

Views: 95

Answers (2)

num3ri
num3ri

Reputation: 776

In 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

Upvotes: 0

Arran Duff
Arran Duff

Reputation: 1444

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

Upvotes: 1

Related Questions