]> git.michaelhowe.org Git - packages/p/paho-mqtt.git/commitdiff
Block in loop_stop() until all messages are sent.
authorRoger Light <roger@atchoo.org>
Sat, 7 Dec 2013 23:40:01 +0000 (23:40 +0000)
committerRoger Light <roger@atchoo.org>
Mon, 3 Feb 2014 21:20:23 +0000 (21:20 +0000)
src/paho/mqtt/client.py

index c8a3486467b7fe6117065eae5a8af9d848a1a755..7cfd1ca32fe1db63600f9369d547cd68500a666a 100755 (executable)
@@ -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