Check whether a connection exists to a remote host using paramiko
I'm using single object of paramiko.SSHClient()
for executing a command on a remote machine. When I use ssh.exec_command(cmd)
, and the connection to remote host is lost, ssh.exec_command
hangs up.
Is there a way to check for connection 开发者_C百科existence before ssh.exec_command()
?
If you have a long running SSH connection, you may want to use the Keep Alive parameter via Transport.set_keepalive.
As an alternate possibility, maybe execnet would work. It wraps the command line ssh command instead, so it's definitely not the paramiko approach... just a though.
精彩评论