Skip to content

Commit

Permalink
Updated queue
Browse files Browse the repository at this point in the history
  • Loading branch information
imbeacon committed Mar 18, 2024
1 parent 63f947c commit 00018ac
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tb_device_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit 00018ac

Please sign in to comment.