Skip to content

Commit 47cbb22

Browse files
author
Panos
committed
Updated parallel commands example
1 parent c48d3db commit 47cbb22

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

examples/parallel_commands.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from pssh import ParallelSSHClient
1+
from pssh.clients import ParallelSSHClient
22
import datetime
33

44
output = []
55
host = 'localhost'
6-
hosts = [host]
6+
hosts = [host, host]
77
client = ParallelSSHClient(hosts)
88

99
# Run 10 five second sleeps
10-
cmds = ['sleep 5' for _ in xrange(10)]
10+
cmds = ['sleep 5; uname' for _ in range(10)]
1111
start = datetime.datetime.now()
1212
for cmd in cmds:
1313
output.append(client.run_command(cmd, stop_on_errors=False))
@@ -17,6 +17,11 @@
1717
start = datetime.datetime.now()
1818
for _output in output:
1919
client.join(_output)
20-
print(_output)
20+
for host_out in _output.values():
21+
for line in host_out.stdout:
22+
print(line)
23+
for line in host_out.stderr:
24+
print(line)
25+
print(f"Exit code: {host_out.exit_code}")
2126
end = datetime.datetime.now()
2227
print("All commands finished in %s" % (end-start,))

0 commit comments

Comments
 (0)