From 138a52611ed63e9fcba170994897c479eaeced40 Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 7 Apr 2018 22:12:17 -0700 Subject: [PATCH] classes: oops, actually tell the queue thread to abort before we wait for it to stop --- classes.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/classes.py b/classes.py index 9c69958..99ddb37 100644 --- a/classes.py +++ b/classes.py @@ -1639,6 +1639,15 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): self._pre_disconnect() + # Stop the queue thread. + 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) + if self._socket is not None: try: selectdriver.unregister(self) @@ -1650,20 +1659,12 @@ class IRCNetwork(PyLinkNetworkCoreWithUtils): except: log.debug('(%s) Error on socket shutdown:', self.name, exc_info=True) + log.debug('(%s) disconnect: waiting for write half of socket %s to shutdown', self.name, self._socket) # Wait for the write half to shut down when applicable. if self._queue_thread is None or self._aborted_send.wait(10): log.debug('(%s) disconnect: closing socket %s', self.name, self._socket) self._socket.close() - # Stop the queue thread. - 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: log.debug('(%s) Canceling pingTimer at %s due to disconnect() call', self.name, time.time())