python paramiko长连接_Python进程由于打开Paramiko ssh连接而挂起

博主在使用Paramiko进行SSH长连接监控远程日志时遇到进程挂起的问题。通过`select`和`channel.recv`进行非阻塞读取,但在网络延迟时仍可能出现挂起。分析了`transport.py`中可能的错误位置,并提供了`lsof`命令的输出以展示挂起的SSH连接。博主希望找到解决方案,但不想因更新Python版本而引入复杂性。
摘要由CSDN通过智能技术生成

我使用Paramiko在测试运行期间监视远程计算机上的日志。在

监视器发生在一个守护进程线程中,该线程几乎可以执行以下操作:ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

transport = ssh.get_transport()

channel = transport.open_session()

channel.exec_command('sudo tail -f ' + self.logfile)

last_partial = ''

while not self.stopped.isSet():

try:

if None == select or None == channel:

break

rl, wl, xl = select.select([channel], [], [], 1.0)

if None == rl:

break

if len(rl) > 0:

# Must be stdout, how can I check?

line = channel.recv(1024)

else:

time.sleep(1.0)

continue

except:

break

if line:

#handle saving the line... lines are 'merged' so that one log is made from all the sources

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值