From 6c65d5523e61fd896df176736e184f45d64a44a7 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sun, 17 Dec 2017 00:36:44 -0800 Subject: [PATCH] IRCNetwork: potentially fix queue thread shutdowns (#558) Replace unreliable appendleft() usage with replacing the first element (or adding None if the queue is empty). --- classes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/classes.py b/classes.py index 77bb216..b7fcc9d 100644 --- a/classes.py +++ b/classes.py @@ -1450,9 +1450,13 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): self._socket.close() # Stop the queue thread. - if self._queue: - # XXX: queue.Queue.queue isn't actually documented, so this is probably not reliable in the long run. - self._queue.queue.appendleft(None) + if self._queue is not None: + try: + # XXX: queue.Queue.queue isn't actually documented, so this is probably not reliable in the long run. + with self._queue.mutex: + self._queue.queue[0] = None + except IndexError: + self._queue.put(None) # Stop the ping timer. if self._ping_timer: