[paramiko] How to use settimeout with from_transport

Robey Pointer robey at lag.net
Mon Mar 26 07:49:33 PDT 2007


On 15 Mar 2007, at 19:18, 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.
>
> I used the following, which seems to work on a per socket basis,  
> though
> it still seems a little hacky to me:
>
> # After I establish the SSH transport connection
> sftp = paramiko.SFTP.from_transport(connection)
> # sftp.sock in this case is actually a paramiko.Channel object
> sftp.sock.settimeout(self._socket_timeout)
>
>
> Robey can probably offer a better sol'n :)

Actually that's the best solution right now. :)

I'll add a get_channel() method to SFTPClient, since this has come up  
before, but it's also fine to access the 'sock' member directly.

robey




More information about the paramiko mailing list