+ while not chan.exit_status_ready() and timeout is not None:
+ if chan.recv_ready():
+ stdout.write(chan.recv(self.__MAX_RECV_BUF))
+
+ if chan.recv_stderr_ready():
+ stderr.write(chan.recv_stderr(self.__MAX_RECV_BUF))
+
+ if time() - start > timeout:
+ raise socket.timeout(
+ 'Timeout exception.\n'
+ 'Current contents of stdout buffer: {0}\n'
+ 'Current contents of stderr buffer: {1}\n'
+ .format(stdout.getvalue(), stderr.getvalue())
+ )
+
+ sleep(0.1)
+ return_code = chan.recv_exit_status()
+
+ while chan.recv_ready():
+ stdout.write(chan.recv(self.__MAX_RECV_BUF))
+
+ while chan.recv_stderr_ready():
+ stderr.write(chan.recv_stderr(self.__MAX_RECV_BUF))
+