From 00018aceff6b84fb6210c2e01e4916caafbc4cd6 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Mon, 18 Mar 2024 13:18:24 +0200 Subject: [PATCH] Updated queue --- tb_device_mqtt.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tb_device_mqtt.py b/tb_device_mqtt.py index 6b49624..e059a54 100644 --- a/tb_device_mqtt.py +++ b/tb_device_mqtt.py @@ -244,6 +244,7 @@ def __put(self, block, timeout): self.__not_full.wait(remaining) def get(self, block=True, timeout=None): + item = None with self.__not_empty: if not block: if not self.__queue: @@ -255,9 +256,9 @@ def get(self, block=True, timeout=None): if remaining <= 0.0: raise TimeoutError("Timeout while trying to get item from queue") self.__not_empty.wait(remaining) - item = self.__queue.pop() + item = self.__queue.popleft() self.__not_full.notify() - return item + return item def put_nowait(self, item): return self.put(item, False) @@ -269,7 +270,7 @@ def full(self): return len(self.__queue) == self.__maxsize def empty(self): - return not self.__queue + return not self.__queue or self.qsize() == 0 def qsize(self): return len(self.__queue) @@ -624,7 +625,8 @@ def __sending_thread_main(self): time.sleep(0.1) continue if not self.__rate_limit.check_limit_reached(): - if not self.__sending_queue.empty(): + if (not self.__sending_queue.empty() + and self.__rate_limit.get_minimal_limit() > len(self._client._out_packet)): item = self.__sending_queue.get(False) if item is not None: info = self._client.publish(item["topic"], item["data"], qos=item["qos"])