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
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

View File

@ -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