I want to run three commands at the same time from python. The command format is query.pl -args
Currently I am doing
os.system("query.pl -results '10000' -serverName 'server1' >> log1.txt")
os.system("query.pl -results '10000' -serverName 'server2' >> log2.txt")
os.system("query.pl -results '10000' -serverName 'server3' >> log3.txt")
I want to query all three servers at the same time but in this case, each command executes only after the last one has finished. How can I make them simultaneous? I was thinking of using '&' at the end but I want the next part of the code to be run only when all three command finish
You could use the subprocess module and have all three running independently: use subprocess.Popen. Take care in setting the "shell" parameter correctly.
Use the wait() or poll() method to determine when the subprocesses are finished.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With