Skip to content

Commit 1806f5e

Browse files
committed
Improve "run multiple clients" example to show the hostname for each task
1 parent ec588e4 commit 1806f5e

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/gather_results.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ async def run_multiple_clients() -> None:
3333
tasks = (run_client(host, 'ls abc') for host in hosts)
3434
results = await asyncio.gather(*tasks, return_exceptions=True)
3535

36-
for i, result in enumerate(results, 1):
36+
for i, result in enumerate(results):
37+
task = f'Task {i+1} to host {hosts[i]}'
38+
3739
if isinstance(result, Exception):
38-
print(f'Task {i} failed: {result}')
40+
print(f'{task} failed: {result}')
3941
elif result.exit_status != 0:
40-
print(f'Task {i} exited with status {result.exit_status}:')
42+
print(f'{task} exited with status {result.exit_status}:')
4143
print(result.stderr, end='')
4244
else:
43-
print(f'Task {i} succeeded:')
45+
print(f'{task} succeeded:')
4446
print(result.stdout, end='')
4547

4648
print(75*'-')

0 commit comments

Comments
 (0)