Check worker status before closing worker

pull/75/head
Sheng 2019-07-03 19:50:35 +08:00
parent ec545ec463
commit 86abf6912d
2 changed files with 7 additions and 8 deletions

View File

@ -462,15 +462,9 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
worker.on_write()
def on_close(self):
if self.close_reason:
logging.info(
'Disconnecting to {}:{} with reason: {reason}'.format(
*self.src_addr, reason=self.close_reason
)
)
else:
logging.info('Disconnected from {}:{}'.format(*self.src_addr))
if not self.close_reason:
self.close_reason = 'client disconnected'
logging.info('Disconnected from {}:{}'.format(*self.src_addr))
worker = self.worker_ref() if self.worker_ref else None
if worker:

View File

@ -29,6 +29,7 @@ class Worker(object):
self.data_to_dst = []
self.handler = None
self.mode = IOLoop.READ
self.closed = False
def __call__(self, fd, events):
if events & IOLoop.READ:
@ -95,6 +96,10 @@ class Worker(object):
self.update_handler(IOLoop.READ)
def close(self, reason=None):
if self.closed:
return
self.closed = True
logging.info(
'Closing worker {} with reason: {}'.format(self.id, reason)
)