Skip to content

Commit

Permalink
Added join convenience function to parallel client and unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
pkittenis committed Oct 20, 2015
1 parent 57ed4d5 commit 109e173
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 9 additions & 1 deletion pssh/pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,15 @@ def _update_host_output(self, output, host, exit_code, channel, stdout, stderr,
'stderr' : stderr,
'cmd' : cmd,
'exception' : exception,})


def join(self, output):
"""Block until all remote commands in output have finished
and retrieve exit codes"""
for host in output:
for line in output[host]['stdout']:
pass
self.get_exit_codes(output)

def get_exit_codes(self, output):
"""Get exit code for all hosts in output *if available*.
Output parameter is modified in-place.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ def test_pssh_client_long_running_command_exit_codes(self):
# Embedded server is also asynchronous and in the same thread
# as our client so need to sleep for duration of server connection
gevent.sleep(expected_lines)
client.pool.join()
client.get_exit_codes(output)
client.join(output)
self.assertTrue(output[self.host]['exit_code'] == 0,
msg="Got non-zero exit code %s" % (
output[self.host]['exit_code'],))
Expand Down

0 comments on commit 109e173

Please sign in to comment.