mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-30 17:50:46 +00:00
ssh: Memoize the SshConnection._get_sftp()
Since we have the guarantee to have a different SshConnection per thread, we can memoize paramiko's SFTPClient. This provides a great performance boost.
This commit is contained in:
parent
55d914bf93
commit
79be8bc5ad
@ -31,6 +31,7 @@ import contextlib
|
||||
import weakref
|
||||
import select
|
||||
import copy
|
||||
import functools
|
||||
from pipes import quote
|
||||
from future.utils import raise_from
|
||||
|
||||
@ -406,6 +407,7 @@ class SshConnection(SshConnectionBase):
|
||||
def _get_progress_cb(self):
|
||||
return self.transfer_mgr.progress_cb if self.transfer_mgr is not None else None
|
||||
|
||||
@functools.lru_cache()
|
||||
def _get_sftp(self, timeout):
|
||||
try:
|
||||
sftp = self.client.open_sftp()
|
||||
@ -417,6 +419,7 @@ class SshConnection(SshConnectionBase):
|
||||
sftp.get_channel().settimeout(timeout)
|
||||
return sftp
|
||||
|
||||
@functools.lru_cache()
|
||||
def _get_scp(self, timeout):
|
||||
return SCPClient(self.client.get_transport(), socket_timeout=timeout, progress=self._get_progress_cb())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user