From d8deaaf4569017de0df9bfb4aad7d02a8bc03a9e Mon Sep 17 00:00:00 2001 From: Cassowary Date: Tue, 30 Apr 2024 09:47:13 -0700 Subject: [PATCH] Catch some of the exceptions that can happen when failing to connect to target host. --- multiball/fabtools.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/multiball/fabtools.py b/multiball/fabtools.py index 307f2ce..fab06c2 100644 --- a/multiball/fabtools.py +++ b/multiball/fabtools.py @@ -5,8 +5,14 @@ from tqdm import tqdm from fabric2 import ThreadingGroup, SerialGroup, Config, Connection +import paramiko + + def thread_run(connection, command, result_lock, result_queue): - res = connection.run(command, warn=True, hide=True) + try: + res = connection.run(command, warn=True, hide=True) + except (paramiko.ssh_exception.NoValidConnectionsError, paramiko.ssh_exception.SSHException) as inst: + res = f"Could not connect to host: {inst}" with result_lock: result_queue.append((connection, res))