From 08ba0c7b0240904df78f2e6102e2d68e111e7bff Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Tue, 11 Aug 2020 22:14:36 +0200 Subject: [PATCH] shut down multiprocessing queue explicitly using a poison pill --- owrx/connection.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/owrx/connection.py b/owrx/connection.py index 6d43579..ceef8c5 100644 --- a/owrx/connection.py +++ b/owrx/connection.py @@ -22,6 +22,8 @@ import logging logger = logging.getLogger(__name__) +PoisonPill = object() + class Client(ABC): def __init__(self, conn): @@ -33,13 +35,15 @@ class Client(ABC): while run: try: data = self.multithreadingQueue.get() - self.send(data) + if data is PoisonPill: + run = False + else: + self.send(data) + self.multithreadingQueue.task_done() except (EOFError, OSError, ValueError): run = False except Exception: logger.exception("Exception on client multithreading queue") - finally: - self.multithreadingQueue.task_done() # unset the queue object to free shared memory file descriptors self.multithreadingQueue = None @@ -53,6 +57,8 @@ class Client(ABC): self.close() def close(self): + if self.multithreadingQueue is not None: + self.multithreadingQueue.put(PoisonPill) self.conn.close() def mp_send(self, data):