[paramiko] How to use settimeout with from_transport
James Bardin
jbardin at bu.edu
Mon Mar 26 08:33:58 PDT 2007
Robey Pointer wrote:
>
> On 16 Mar 2007, at 6:54, James Bardin wrote:
>
>>
>>
>> Todd Whiteman wrote:
>>> James Bardin wrote:
>>>> I've wondered how to do this myself, and I have a method that works,
>>>> but maybe someone will let us know if there's a better way.
>>>>
>>>> My program uses a large number of connections simultaneously, so to
>>>> set a short timeout for everything I do the following:
>>>>
>>>> from socket import setdefaulttimeout
>>>> setdefaulttimeout(2)
>>>>
>>>
>>> Ouch, thats global settings for socket timeout.
>>>
>> Yeah, it was a quick fix, but a global setting actually works in this
>> case.
>> I didn't see sftp.sock, because it doesn't show up until you build the
>> object.
>> Even when I go back and look at the docs now, I don't see where you
>> would find how to access the socket settings in a connection.
>>
>> I still need to set timeouts for the SSHClient() though, and it look
>> wrong to use
>> client = SSHClient()
>> client._transport.sock.settimeout()
>> when he's implying that _transport is private.
>
> Timeouts on the socket object are handled at a different level in
> paramiko, so it can check for status changes while doing I/O.
>
> It looks like the socket timeout is set to 0.1 inside Transport, so
> I'd be surprised if setting the socket timeout manually to 2 had any
> effect other than making a few status changes more sluggish.
>
> robey
>
>
My case is a little unusual.
It's actually before the transport is built where I have problems.
I need to connect to a very large number of hosts simultaneously, some
of which may or may not be working properly. I want the connection to
drop if I can't build a channel within a few seconds.
The catch is that sometimes the host is up, but the ssh daemon isn't
responding, so I don't get a "No route to host", and we hang.
I'm trying to replicate an option like "-o ConnectTimeout=2" from ssh.
BTW, I like the SSHClient class. It abstracts exactly what I need (not
counting the above).
Thanks,
-jim
More information about the paramiko
mailing list