[paramiko] How to use settimeout with from_transport

Robey Pointer robey at lag.net
Mon Mar 26 07:52:29 PDT 2007


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




More information about the paramiko mailing list