def wait_for_at_least_one_message(self, channel):
        """
        Reads until we receive at least one message we can unpack. Return all found messages.
        """

        unpacker = msgpack.Unpacker(encoding='utf-8')

        while True:
            try:
                start = time.time()
                chunk = self.ssh_channel[channel].recv(1024)
                end = time.time()
                self.read_speeds.append( len(chunk) / (end-start) )
                if len(self.read_speeds) > 20:
                    self.read_speeds = self.read_speeds[10:]

                if chunk == b'':
                    # happens only when connection broke. If nothing is to be received, it hangs instead.
                    self.connection_error(channel, 'Connection broken w')
                    return False
            except Exception as error:
                self.connection_error(channel, error)
                raise

            unpacker.feed(chunk)

            messages = [m for m in unpacker]
            if messages:
                return messages
def wait_for_at_least_one_message ( self , channel ) : unpacker = msgpack . Unpacker ( encoding = 'utf-8' ) while True : try : start = time . time ( ) chunk = self . ssh_channel [ channel ] . recv ( 1024 ) end = time . time ( ) self . read_speeds . append ( len ( chunk ) / ( end - start ) ) if len ( self . read_speeds ) > 20 : self . read_speeds = self . read_speeds [ 10 : ] if chunk == b'' : self . connection_error ( channel , 'Connection broken w' ) return False except Exception as error : self . connection_error ( channel , error ) raise unpacker . feed ( chunk ) messages = [ m for m in unpacker ] if messages : return messages
Reads until we receive at least one message we can unpack. Return all found messages.