当由 unittest runner 运行时,Paramiko 在身份验证期间挂起 [英] Paramiko hanging during authentication, when runned by dint of unittest runner

查看:49
本文介绍了当由 unittest runner 运行时,Paramiko 在身份验证期间挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天.

paramiko ssh 客户端有一个奇怪的问题.Connect paramiko 方法在 unittest2 类/函数之外被调用并且代码由 unittest runner 运行时挂起.

I have a strange problem with paramiko ssh client. Connect paramiko method hangs when it's called outside unittest2 classes/functions and code was run by unittest runner.

有一段代码,出现问题:

There is a piece of code, where problem appears:

import paramiko
import unittest2

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('172.18.67.10',
            username='root',
            password='secrete')
_, stdout, _ = ssh.exec_command('date')


class TestTest(unittest2.TestCase):
    def setUp(self):
        pass

如果我将 ssh.connect 移动到 TestTest 类或 setUpModule 函数中,连接将成功.当代码由原始 Python 解释器运行时,一切正常.

If I move ssh.connect into TestTest class or setUpModule function, connection will be successful. Also everything is OK when code is run by original Python interpreter.

当我尝试调试 paramiko 时,我在 paramiko/auth_handler.py:AuthHandler.wait_for_response 方法中的 while True 循环中发现了这个问题.

When I try to debug paramiko, I figure out this problem inside while True loop in paramiko/auth_handler.py:AuthHandler.wait_for_response method.

有什么建议吗?

推荐答案

根据 this SO answer,似乎是 paramiko 中与线程相关的错误,可以通过在导入期间不调用 connect() 来避免.

According to this SO answer, it seems to be a thread-related bug in paramiko and can be avoided by not calling connect() during import.

这篇关于当由 unittest runner 运行时,Paramiko 在身份验证期间挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆