mirror of https://github.com/huashengdun/webssh
Check worker status before closing worker
parent
ec545ec463
commit
86abf6912d
|
@ -462,15 +462,9 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
|
||||||
worker.on_write()
|
worker.on_write()
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
if self.close_reason:
|
logging.info('Disconnected from {}:{}'.format(*self.src_addr))
|
||||||
logging.info(
|
if not self.close_reason:
|
||||||
'Disconnecting to {}:{} with reason: {reason}'.format(
|
|
||||||
*self.src_addr, reason=self.close_reason
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.close_reason = 'client disconnected'
|
self.close_reason = 'client disconnected'
|
||||||
logging.info('Disconnected from {}:{}'.format(*self.src_addr))
|
|
||||||
|
|
||||||
worker = self.worker_ref() if self.worker_ref else None
|
worker = self.worker_ref() if self.worker_ref else None
|
||||||
if worker:
|
if worker:
|
||||||
|
|
|
@ -29,6 +29,7 @@ class Worker(object):
|
||||||
self.data_to_dst = []
|
self.data_to_dst = []
|
||||||
self.handler = None
|
self.handler = None
|
||||||
self.mode = IOLoop.READ
|
self.mode = IOLoop.READ
|
||||||
|
self.closed = False
|
||||||
|
|
||||||
def __call__(self, fd, events):
|
def __call__(self, fd, events):
|
||||||
if events & IOLoop.READ:
|
if events & IOLoop.READ:
|
||||||
|
@ -95,6 +96,10 @@ class Worker(object):
|
||||||
self.update_handler(IOLoop.READ)
|
self.update_handler(IOLoop.READ)
|
||||||
|
|
||||||
def close(self, reason=None):
|
def close(self, reason=None):
|
||||||
|
if self.closed:
|
||||||
|
return
|
||||||
|
self.closed = True
|
||||||
|
|
||||||
logging.info(
|
logging.info(
|
||||||
'Closing worker {} with reason: {}'.format(self.id, reason)
|
'Closing worker {} with reason: {}'.format(self.id, reason)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue