New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout parameterization to exec_command() #113

Closed
bitprophet opened this Issue Nov 26, 2012 · 0 comments

Comments

Projects
None yet
1 participant
@bitprophet
Member

bitprophet commented Nov 26, 2012

See patch attached to Fabric #249 EDIT: actually, don't, that had to go a different route because $REASONS :( Reproducing patch below:

From 007fedc94b4cbb390e7413bec0a55cdf74ab8c24 Mon Sep 17 00:00:00 2001
From: cernov <cernov@[REDACTED].com>
Date: Fri, 16 Nov 2012 11:58:00 +0200
Subject: [PATCH] Added an extra parameter (timeout) to exec_command

---
 paramiko/client.py |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/paramiko/client.py b/paramiko/client.py
index 07560a3..0e53b41 100644
--- a/paramiko/client.py
+++ b/paramiko/client.py
@@ -350,7 +350,7 @@ class SSHClient (object):
             self._agent.close()
             self._agent = None

-    def exec_command(self, command, bufsize=-1):
+    def exec_command(self, command, bufsize=-1, timeout=None):
         """
         Execute a command on the SSH server.  A new L{Channel} is opened and
         the requested command is executed.  The command's input and output
@@ -361,12 +361,15 @@ class SSHClient (object):
         @type command: str
         @param bufsize: interpreted the same way as by the built-in C{file()} function in python
         @type bufsize: int
+        @param timeout: maximum time to wait for command to execute
+        @type timeout: float
         @return: the stdin, stdout, and stderr of the executing command
         @rtype: tuple(L{ChannelFile}, L{ChannelFile}, L{ChannelFile})

         @raise SSHException: if the server fails to execute the command
         """
         chan = self._transport.open_session()
+        chan.settimeout(timeout)
         chan.exec_command(command)
         stdin = chan.makefile('wb', bufsize)
         stdout = chan.makefile('rb', bufsize)
-- 
1.7.9.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment