From af31320c67bd0b5e7bfc7c6ee0c62c94297089ec Mon Sep 17 00:00:00 2001 From: Roger Light Date: Sat, 7 Dec 2013 23:40:01 +0000 Subject: [PATCH] Block in loop_stop() until all messages are sent. --- src/paho/mqtt/client.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 -- 2.39.5