handle shutdown in receivequeuethread
- sometimes during shutdown, the receivequeuethread would get stuck
This commit is contained in:
parent
391d40d78b
commit
7b470d4b66
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user