I'm trying to get Python paramiko timeout on connect(). It works for many hosts but with one in particular, it just never timeout. Here is my code :
# python3
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
...
>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect(hostname="10.68.45.210", username="root", password="a_none_working_pass", timeout=2)
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 307, in connect
look_for_keys, gss_auth, gss_kex, gss_deleg_creds, gss_host)
File "/usr/lib/python3/dist-packages/paramiko/client.py", line 510, in _auth
self._transport.auth_password(username, password)
File "/usr/lib/python3/dist-packages/paramiko/transport.py", line 1166, in auth_password
return self.auth_handler.wait_for_response(my_event)
File "/usr/lib/python3/dist-packages/paramiko/auth_handler.py", line 192, in wait_for_response
event.wait(0.1)
File "/usr/lib/python3.4/threading.py", line 553, in wait
signaled = self._cond.wait(timeout)
File "/usr/lib/python3.4/threading.py", line 294, in wait
gotit = waiter.acquire(True, timeout)
KeyboardInterrupt
What am I doing wrong?
I've done an strace of the process and when it hangs, I obtain these messages in loop:
select(0, NULL, NULL, NULL, {0, 1000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 4000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 8000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 16000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 32000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 36139}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 1000}) = 0 (Timeout)
select(0, NULL, NULL, NULL, {0, 2000}) = 0 (Timeout)
Tried on Debian Jessie with Python 2.7.3 and 3.4.2 and both hangs in an infinite loop.
EDIT: Seems to be related with this SO topic: Why does Paramiko hang if you use it while loading a module? but is there a way to shelve of this issue?