如何在超时的情况下杀死 paramiko exec_command 中的所有命令子进程和孙子

问题描述 投票:0回答:1
client = paramiko.SSHClient()
client.connect(<host details...>)
try:
    stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout)
    err = stderr.channel.recv_stderr(sys.maxsize)
    exit_code = stdout.channel.recv_exit_status()
 except socket.timeout:
    # Need to kill all descendants of the exec_command process

我试图在命令之前添加 bash 超时,但是有一些带有';'的链接命令

python ssh timeout paramiko
1个回答
0
投票

需要运行 exec_command with get_pty=True,那么什么时候做 client.close() 它也会杀死所有的孩子

© www.soinside.com 2019 - 2024. All rights reserved.