From: Roger Light Date: Sat, 7 Dec 2013 23:40:01 +0000 (+0000) Subject: Block in loop_stop() until all messages are sent. X-Git-Tag: v0.9~41 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=af31320c67bd0b5e7bfc7c6ee0c62c94297089ec;p=packages%2Fp%2Fpaho-mqtt.git Block in loop_stop() until all messages are sent. --- diff --git a/src/paho/mqtt/client.py b/src/paho/mqtt/client.py index c8a3486..7cfd1ca 100755 --- a/src/paho/mqtt/client.py +++ b/src/paho/mqtt/client.py @@ -1152,7 +1152,16 @@ class Client: rc = MQTT_ERR_SUCCESS while rc == MQTT_ERR_SUCCESS: rc = self.loop(timeout, max_packets) - if self._thread_terminate is True: + # We don't need to worry about locking here, because we've + # either called loop_forever() when in single threaded mode, or + # in multi threaded mode when loop_stop() has been called and + # so no other threads can access _current_out_packet, + # _out_packet or _messages. + if (self._thread_terminate is True + and self._current_out_packet is None + and len(self._out_packet) == 0 + and len(self._messages) == 0): + rc = 1 run = False