@@ -105,7 +105,6 @@ def _open_shell(self, host_i, host,
105105 encoding = encoding , read_timeout = read_timeout )
106106 return shell
107107 except (GTimeout , Exception ) as ex :
108- host = ex .host if hasattr (ex , 'host' ) else None
109108 logger .error ("Failed to run on host %s - %s" , host , ex )
110109 raise ex
111110
@@ -199,17 +198,17 @@ def run_command(self, command, user=None, stop_on_errors=True,
199198 return self ._get_output_from_cmds (cmds , raise_error = stop_on_errors )
200199
201200 def _get_output_from_cmds (self , cmds , raise_error = False ):
202- _cmds = [spawn (self ._get_output_from_greenlet , cmd , raise_error = raise_error )
203- for cmd in cmds ]
201+ _cmds = [spawn (self ._get_output_from_greenlet , cmd_i , cmd , raise_error = raise_error )
202+ for cmd_i , cmd in enumerate ( cmds ) ]
204203 finished = joinall (_cmds , raise_error = True )
205204 return [f .get () for f in finished ]
206205
207- def _get_output_from_greenlet (self , cmd , raise_error = False ):
206+ def _get_output_from_greenlet (self , cmd_i , cmd , raise_error = False ):
207+ host = self .hosts [cmd_i ]
208208 try :
209209 host_out = cmd .get ()
210210 return host_out
211211 except (GTimeout , Exception ) as ex :
212- host = ex .host if hasattr (ex , 'host' ) else None
213212 if isinstance (ex , GTimeout ):
214213 ex = Timeout ()
215214 if raise_error :
@@ -266,7 +265,6 @@ def _run_command(self, host_i, host, command, sudo=False, user=None,
266265 use_pty = use_pty , encoding = encoding , read_timeout = read_timeout )
267266 return host_out
268267 except (GTimeout , Exception ) as ex :
269- host = ex .host if hasattr (ex , 'host' ) else None
270268 logger .error ("Failed to run on host %s - %s" , host , ex )
271269 raise ex
272270
@@ -312,7 +310,7 @@ def join(self, output=None, consume_output=False, timeout=None):
312310 self.pool.
313311 Since self.timeout is passed onto each individual SSH session it is
314312 **not** used for any parallel functions like `run_command` or `join`.
315- :type timeout: int
313+ :type timeout: float
316314
317315 :raises: :py:class:`pssh.exceptions.Timeout` on timeout requested and
318316 reached with commands still running.
@@ -431,13 +429,9 @@ def copy_file(self, local_file, remote_file, recurse=False, copy_args=None):
431429
432430 def _copy_file (self , host_i , host , local_file , remote_file , recurse = False ):
433431 """Make sftp client, copy file"""
434- try :
435- self ._make_ssh_client (host_i , host )
436- return self ._host_clients [(host_i , host )].copy_file (
437- local_file , remote_file , recurse = recurse )
438- except Exception as ex :
439- ex .host = host
440- raise ex
432+ client = self ._make_ssh_client (host_i , host )
433+ return client .copy_file (
434+ local_file , remote_file , recurse = recurse )
441435
442436 def copy_remote_file (self , remote_file , local_file , recurse = False ,
443437 suffix_separator = '_' , copy_args = None , ** kwargs ):
@@ -518,19 +512,14 @@ def copy_remote_file(self, remote_file, local_file, recurse=False,
518512 def _copy_remote_file (self , host_i , host , remote_file , local_file , recurse ,
519513 ** kwargs ):
520514 """Make sftp client, copy file to local"""
521- try :
522- self ._make_ssh_client (host_i , host )
523- return self ._host_clients [(host_i , host )].copy_remote_file (
524- remote_file , local_file , recurse = recurse , ** kwargs )
525- except Exception as ex :
526- ex .host = host
527- raise ex
515+ client = self ._make_ssh_client (host_i , host )
516+ return client .copy_remote_file (
517+ remote_file , local_file , recurse = recurse , ** kwargs )
528518
529519 def _handle_greenlet_exc (self , func , host , * args , ** kwargs ):
530520 try :
531521 return func (* args , ** kwargs )
532522 except Exception as ex :
533- ex .host = host
534523 raise ex
535524
536525 def _make_ssh_client (self , host_i , host ):
0 commit comments