问题
Good day.
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
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.
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
.
Any suggestions?
回答1:
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.
来源:https://stackoverflow.com/questions/13155890/paramiko-hanging-during-authentication-when-runned-by-dint-of-unittest-runner