[paramiko] How to use settimeout with from_transport
James Bardin
jbardin at bu.edu
Fri Mar 16 06:54:07 PDT 2007
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.
-jim
> 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 :)
>
> Cheers,
> Todd
>
>
More information about the paramiko
mailing list