From 7b470d4b6665da8d9cdbf7038611ba817adcacdc Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 19 Oct 2017 09:11:34 +0200 Subject: [PATCH] handle shutdown in receivequeuethread - sometimes during shutdown, the receivequeuethread would get stuck --- src/network/advanceddispatcher.py | 8 +++++--- src/network/receivequeuethread.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/network/advanceddispatcher.py b/src/network/advanceddispatcher.py index 2115c454..35121d1c 100644 --- a/src/network/advanceddispatcher.py +++ b/src/network/advanceddispatcher.py @@ -5,6 +5,7 @@ import time import asyncore_pollchoose as asyncore from debug import logger from helper_threading import BusyError, nonBlocking +import state class AdvancedDispatcher(asyncore.dispatcher): _buf_len = 2097152 # 2MB @@ -50,16 +51,17 @@ class AdvancedDispatcher(asyncore.dispatcher): del self.read_buf[0:length] def process(self): - if not self.connected: - return False - while True: + while self.connected and not state.shutdown: try: with nonBlocking(self.processingLock): + if not self.connected or state.shutdown: + break if len(self.read_buf) < self.expectBytes: return False if getattr(self, "state_" + str(self.state))() is False: break except AttributeError: + logger.error("Unknown state %s", self.state) raise except BusyError: return False diff --git a/src/network/receivequeuethread.py b/src/network/receivequeuethread.py index a617e16e..5399b972 100644 --- a/src/network/receivequeuethread.py +++ b/src/network/receivequeuethread.py @@ -30,7 +30,7 @@ class ReceiveQueueThread(threading.Thread, StoppableThread): except Queue.Empty: continue - if self._stopped: + if self._stopped or state.shutdown: break # cycle as long as there is data