code: def subscribe(self, topic, qos, timeout=1, limit=1):
          
          seconds = convert_time(timeout)
          self._messages[topic] = []
          limit = int(limit)
          self._subscribed = False
  
          logger.info('Subscribing to topic: %s' % topic)
          self._mqttc.on_subscribe = self._on_subscribe
          self._mqttc.subscribe(str(topic), int(qos))
          self._mqttc.on_message = self._on_message_list
  
          if seconds == 0:
              logger.info('Starting background loop')
              self._background_mqttc = self._mqttc
              self._background_mqttc.loop_start()
              return self._messages[topic]
  
          timer_start = time.time()
          while time.time() < timer_start + seconds:
              if limit == 0 or len(self._messages[topic]) < limit:
                  self._mqttc.loop()
              else:
                  # workaround for client to ack the publish. Otherwise,
                  # it seems that if client disconnects quickly, broker
                  # will not get the ack and publish the message again on
                  # next connect.
                  time.sleep(1)
                  break
          return self._messages[topic]
docs: Subscribe to a topic and return a list of message payloads received
              within the specified time.
  
          `topic` topic to subscribe to
  
          `qos` quality of service for the subscription
  
          `timeout` duration of subscription. Specify 0 to enable background looping (async)
  
          `limit` the max number of payloads that will be returned. Specify 0
              for no limit
  
          Examples:
  
          Subscribe and get a list of all messages received within 5 seconds
          | ${messages}= | Subscribe | test/test | qos=1 | timeout=5 | limit=0 |
  
          Subscribe and get 1st message received within 60 seconds
          | @{messages}= | Subscribe | test/test | qos=1 | timeout=60 | limit=1 |
          | Length should be | ${messages} | 1 |