From: Roger Light Date: Mon, 26 Aug 2013 19:55:59 +0000 (+0100) Subject: Improve handling of disconnect() with threaded mode. X-Git-Tag: v0.9~54 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=a0d3552900bb05dcfc4ee1d79f12f2d75a0f3de8;p=packages%2Fp%2Fpaho-mqtt.git Improve handling of disconnect() with threaded mode. --- diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index c80fabd..9001bb5 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -780,13 +780,13 @@ class Client: def disconnect(self): """Disconnect a connected client from the broker.""" - if self._sock == None and self._ssl == None: - return MQTT_ERR_NO_CONN - self._state_mutex.acquire() self._state = mqtt_cs_disconnecting self._state_mutex.release() + if self._sock == None and self._ssl == None: + return MQTT_ERR_NO_CONN + return self._send_disconnect() def subscribe(self, topic, qos=0): @@ -1031,6 +1031,15 @@ class Client: else: self._state_mutex.release() time.sleep(1) + + self._state_mutex.acquire() + if self._state == mosq_cs_disconnecting: + run = False + self._state_mutex.release() + else: + self._state_mutex.release() + self.reconnect() + self.reconnect() return rc