[paramiko] Add timeout for exe_command() ?
james bardin
jbardin at bu.edu
Fri Jan 15 07:41:40 PST 2010
On Fri, Jan 15, 2010 at 5:18 AM, Wan Li <wanliyou at gmail.com> wrote:
>
>> Shall I simply call ssh.close() first and login again to make the retry
>> works? Or maybe there is a way to cancel the exe_command?
>>
>
> I spend some time looking into paramiko. Here are thoughts in my mind,
> correct me if I'm wrong. :-)
>
> Basically, we initialize a SSHClient, call connect() to establish the
> connection(a new Transport), exe_command will call the open_session() to add
> a new channel for this transport which will be stored in
> Transport._channels. If I wanna cancel the exe_command, the best way may be
> simply call ssh._transport._channels[ssh._transport.channel_count].close()
> to close the previous channel and call the exe_command() again.
>
That's probably not a good way to go about it. There's no guarantee
that ssh._transport._channels[ssh._transport.channel_count] will
return the channel you expect
(not to mention, _transport and _channels are marked private).
Just take the transport (get_transport), and run exec_command() on
your own. SSHClient.exec_command is only 5 lines of code, and then you
can do whatever you want with the channel.
-jim
More information about the paramiko
mailing list