How can i use aysncio with subprocess in python to run commands on multiple boxes without waiting for subprocess to return output for each box?

Viewed 23

Here is the snippet of my code. i want to start up the app on server A, then go B and then to C without waiting on the output from A.

import subprocess 
machine_list = ["A","B","C"]  

def start(machine):  
    start_cmd = "/home/users/start.sh"  
    start_process_status = subprocess.Popen(start_cmd,
    stdout=subprocess.PIPE, stdin=subprocess.PIPE, universal_newlines=True, shell=True)  
    output, errors = start_process_status.communicate()
    output = output.split("\n")  
    print("Start app output on {} : {} ".format(machine, output))  

for machine in machine_map:  
    start(machine)
0 Answers
Related