From 3030589aaafdba0a3b14183e0d03488580d21bf5 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Tue, 17 Jan 2012 12:10:57 -0800 Subject: [PATCH] Add IO sleep to agent forward communications. Without this, use of agent forwarding causes high CPU usage on some clients. --- ssh/__init__.py | 5 ++++- ssh/agent.py | 2 ++ ssh/common.py | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ssh/__init__.py b/ssh/__init__.py index 86dde0f..f00da10 100644 --- a/ssh/__init__.py +++ b/ssh/__init__.py @@ -98,6 +98,8 @@ from common import AUTH_SUCCESSFUL, AUTH_PARTIALLY_SUCCESSFUL, AUTH_FAILED, \ from sftp import SFTP_OK, SFTP_EOF, SFTP_NO_SUCH_FILE, SFTP_PERMISSION_DENIED, SFTP_FAILURE, \ SFTP_BAD_MESSAGE, SFTP_NO_CONNECTION, SFTP_CONNECTION_LOST, SFTP_OP_UNSUPPORTED +from common import io_sleep + __all__ = [ 'Transport', 'SSHClient', 'MissingHostKeyPolicy', @@ -131,4 +133,5 @@ __all__ = [ 'Transport', 'AgentKey', 'HostKeys', 'SSHConfig', - 'util' ] + 'util', + 'io_sleep' ] diff --git a/ssh/agent.py b/ssh/agent.py index d8c52f1..e613531 100644 --- a/ssh/agent.py +++ b/ssh/agent.py @@ -34,6 +34,7 @@ from ssh.ssh_exception import SSHException from ssh.message import Message from ssh.pkey import PKey from ssh.channel import Channel +from ssh.common import io_sleep SSH2_AGENTC_REQUEST_IDENTITIES, SSH2_AGENT_IDENTITIES_ANSWER, \ SSH2_AGENTC_SIGN_REQUEST, SSH2_AGENT_SIGN_RESPONSE = range(11, 15) @@ -134,6 +135,7 @@ class AgentProxyThread(threading.Thread): self._agent._conn.send(data) else: break + time.sleep(io_sleep) class AgentLocalProxy(AgentProxyThread): """ diff --git a/ssh/common.py b/ssh/common.py index 8f6a77c..4858200 100644 --- a/ssh/common.py +++ b/ssh/common.py @@ -124,3 +124,6 @@ INFO = logging.INFO WARNING = logging.WARNING ERROR = logging.ERROR CRITICAL = logging.CRITICAL + +# Common IO/select/etc sleep period, in seconds +io_sleep = 0.01