I saw some useful information in this post about how you can't expect to run a process in the background if you are retrieving output from it using subprocess
. The problem is ... this is exactly what I want to do!
I have a script which drops commands to various hosts via ssh
and I don't want to have to wait on each one to finish before starting the next. Ideally, I could have something like this:
for host in hostnames:
p[host] = Popen(["ssh", mycommand], stdout=PIPE, stderr=PIPE)
pout[host], perr[host] = p[host].communicate()
which would have (in the case where mycommand
takes a very long time) all of the hosts running mycommand
at the same time. As it is now, it appears that the entirety of the ssh command finishes before starting the next. This is (according to the previous post I linked) due to the fact that I am capturing output, right? Other than just cat
ing the output to a file and reading the output later, is there a decent way to make these things happen on various hosts in parallel?