code: def connect(self):
          
          if not self.connect_attempted:
              self.connect_attempted = True
              self.client.connect(self.host, port=self.port)
              self.client.loop_start()
  
              while not self.connected:
                  log.info('waiting for MQTT connection...')
                  time.sleep(1)
docs: Connect to MQTT server and wait for server to acknowledge