Make is_running protected member.

This commit is contained in:
Yuxin Wang 2018-09-30 11:00:11 -04:00
parent f34e96b077
commit b3eaf0c33c

View file

@ -16,7 +16,7 @@ class MessageServer:
self._compressor = zstd.ZstdCompressor()
self._decompressor = zstd.ZstdDecompressor()
self.is_running = True
self._is_running = True
def start(self):
self._sock.listen(5)
@ -26,18 +26,18 @@ class MessageServer:
self._server_started()
def stop(self):
self.is_running = False
self._is_running = False
self._sock.close()
def _listen(self):
try:
while self.is_running:
while self._is_running:
client, address = self._sock.accept()
logger.info('New connection from {}'.format(address))
self._client_connected(client)
threading.Thread(target=self._read_message, args=(client,)).start()
except ConnectionAbortedError or OSError as e:
if self.is_running:
if self._is_running:
# if exception occurred during normal execution
logger.error(e)
else: