I'm using fabric.api to run command in the remote machine. The snippet of my code looks like this:
import time
import sys
from fabric.api import *
from fabric.api import env, run, task, hide, execute
ssh_key = <something>
ssh_key_passphase = <something>
env.host_string = <something>
env.user = <something>
env.port = 22
def execute_command_in_remote(cmd):
env.user = ssh_user
env.key_filename = ssh_key
env.password = ssh_key_passphase
result = run(cmd)
return result
result=execute_command_in_remote(<some commands>)
....
....
While the command is being executed in the remote, if ssh connection is broken(due to the host restart), the program gets stuck. How can I get a signal about the broken ssh connection?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…