Server disconnection works properly

This commit is contained in:
nemunaire 2014-08-31 10:51:44 +02:00
parent dcce36eb7c
commit 038590c659
4 changed files with 5 additions and 5 deletions

2
bot.py
View File

@ -394,7 +394,7 @@ class Bot(threading.Thread):
logger.info("Close all servers connection...")
k = list(self.servers.keys())
for srv in k:
self.servers[srv].disconnect()
self.servers[srv].close()
self.stop = True

View File

@ -87,6 +87,4 @@ if __name__ == "__main__":
print ("\nWaiting for other threads shuts down...")
# Indeed, the server socket is waiting for receiving some data
sys.exit(0)

View File

@ -70,9 +70,10 @@ class AbstractServer(io.IOBase):
def write_select(self):
"""Internal function used by the select function"""
try:
_wlist.remove(self)
while not self._sending_queue.empty():
self._write(self._sending_queue.get_nowait())
_wlist.remove(self)
self._sending_queue.task_done()
except queue.Empty:
pass

View File

@ -57,8 +57,9 @@ class SocketServer(AbstractServer):
return True
def _close(self):
self._sending_queue.join()
if self.socket is not None:
self.socket.shutdown(SHUT_RDWR)
self.socket.shutdown(socket.SHUT_RDWR)
self.socket.close()
self.socket = None