handle shutdown in receivequeuethread

- sometimes during shutdown, the receivequeuethread would get
stuck
This commit is contained in:
Peter Šurda 2017-10-19 09:11:34 +02:00
parent 391d40d78b
commit 7b470d4b66
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
2 changed files with 6 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import time
import asyncore_pollchoose as asyncore import asyncore_pollchoose as asyncore
from debug import logger from debug import logger
from helper_threading import BusyError, nonBlocking from helper_threading import BusyError, nonBlocking
import state
class AdvancedDispatcher(asyncore.dispatcher): class AdvancedDispatcher(asyncore.dispatcher):
_buf_len = 2097152 # 2MB _buf_len = 2097152 # 2MB
@ -50,16 +51,17 @@ class AdvancedDispatcher(asyncore.dispatcher):
del self.read_buf[0:length] del self.read_buf[0:length]
def process(self): def process(self):
if not self.connected: while self.connected and not state.shutdown:
return False
while True:
try: try:
with nonBlocking(self.processingLock): with nonBlocking(self.processingLock):
if not self.connected or state.shutdown:
break
if len(self.read_buf) < self.expectBytes: if len(self.read_buf) < self.expectBytes:
return False return False
if getattr(self, "state_" + str(self.state))() is False: if getattr(self, "state_" + str(self.state))() is False:
break break
except AttributeError: except AttributeError:
logger.error("Unknown state %s", self.state)
raise raise
except BusyError: except BusyError:
return False return False

View File

@ -30,7 +30,7 @@ class ReceiveQueueThread(threading.Thread, StoppableThread):
except Queue.Empty: except Queue.Empty:
continue continue
if self._stopped: if self._stopped or state.shutdown:
break break
# cycle as long as there is data # cycle as long as there is data