code: def disconnect(self):
          
          # Stop the timer
          self.__stop_timer()
  
          # Unlock all publishers
          for event in self.__in_flight.values():
              event.set()
  
          # Disconnect from the server
          self.__mqtt.disconnect()
  
          # Stop the MQTT loop thread
          # Use a thread to avoid a dead lock in Paho
          thread = threading.Thread(target=self.__mqtt.loop_stop)
          thread.daemon = True
          thread.start()
  
          # Give it some time
          thread.join(4)
docs: Disconnects from the MQTT server