From e10a52b39e8901535e9e4e3c6a8c5e9b702ff393 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 15 Sep 2020 22:04:53 +0200 Subject: [PATCH] handle full queue better by draining --- owrx/connection.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/owrx/connection.py b/owrx/connection.py index 7bfd805..9672f7a 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -12,7 +12,7 @@ from owrx.bookmarks import Bookmarks from owrx.map import Map from owrx.property import PropertyStack from owrx.modes import Modes, DigitalMode -from queue import Queue, Full +from queue import Queue, Full, Empty from js8py import Js8Frame from abc import ABC, ABCMeta, abstractmethod import json @@ -58,7 +58,16 @@ class Client(ABC): def close(self): if self.multithreadingQueue is not None: - self.multithreadingQueue.put(PoisonPill) + while True: + try: + self.multithreadingQueue.get(block=False) + except Empty: + break + try: + self.multithreadingQueue.put(PoisonPill, block=False) + except Full: + # this shouldn't happen, we just emptied the queue, but it's not worth risking the exception + logger.exception("impossible queue state: Full after Empty") self.conn.close() def mp_send(self, data):