[paramiko] ssh.exec_command() hangs up

james bardin jbardin at bu.edu
Wed Nov 25 07:25:12 PST 2009


On Wed, Nov 25, 2009 at 5:51 AM, himanchali <himanchali at inmobi.com> wrote:
> hi james,
> Its not working.  Transport.set_keepalive() is not working, after that also
>  is _alive() is returning true...

is_alive() is a thread method, it's not relevant here.

> i cant use open_session() also  as it hangs up if connection is not
> available.
>

If by "hangs up" you mean that it waits indefinitely, then that is the
expected behavior.


> Pls remember, that i have to use single object of paramiko.SSHClient() on a
> machine, so i cant close it.
>

You may nee to re-architect your solution then, but there's no reason
you couldn't call connect() again from the same object, which would
create a new socket and transport. Depending on what your VPN,
firewall, server all do, this could hang, or return exceptions like
(101, 'Network is unreachable'), (111, 'Connection refused'), or a
socket.timeout if you've set the timeout parameter.


> There should be some way to check for connection existence before
> ssh.exec_command()????
> pls help.


This isn't a paramiko problem, this is a network problem. If I connect
using openssh, and then proceed to null route the packets, the
connection will hang just like it does in paramiko. SSH depends on a
reliable connection over an unreliable network. If a client sends
packets out of an open socket, all it can do is hope they get there,
wait for a response, and keep trying. When your VPN connection goes
down, your packets fall into a blackhole, and there's no way for the
client to tell. This can only be as reliable as TCP.


-jim



More information about the paramiko mailing list