Skip to content

Commit

Permalink
Updated parallel commands example
Browse files Browse the repository at this point in the history
  • Loading branch information
Panos committed Aug 25, 2020
1 parent c48d3db commit 47cbb22
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions examples/parallel_commands.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pssh import ParallelSSHClient
from pssh.clients import ParallelSSHClient
import datetime

output = []
host = 'localhost'
hosts = [host]
hosts = [host, host]
client = ParallelSSHClient(hosts)

# Run 10 five second sleeps
cmds = ['sleep 5' for _ in xrange(10)]
cmds = ['sleep 5; uname' for _ in range(10)]
start = datetime.datetime.now()
for cmd in cmds:
output.append(client.run_command(cmd, stop_on_errors=False))
Expand All @@ -17,6 +17,11 @@
start = datetime.datetime.now()
for _output in output:
client.join(_output)
print(_output)
for host_out in _output.values():
for line in host_out.stdout:
print(line)
for line in host_out.stderr:
print(line)
print(f"Exit code: {host_out.exit_code}")
end = datetime.datetime.now()
print("All commands finished in %s" % (end-start,))

0 comments on commit 47cbb22

Please sign in to comment.