Commit 9698e4f8 authored by ibuler's avatar ibuler

[Update] 修改coco,解决退出有时延的问题

parent 0ad0a272
......@@ -125,6 +125,10 @@ class Coco:
else:
return True
def heartbeat_async(self):
t = threading.Thread(target=self.heartbeat)
t.start()
def handle_task(self, tasks):
for task in tasks:
self.task_handler.handle(task)
......@@ -212,15 +216,10 @@ class Coco:
def add_session(self, session):
with self.lock:
self.sessions.append(session)
self.heartbeat()
self.heartbeat_async()
def remove_session(self, session):
with self.lock:
logger.info("Remove session: {}".format(session))
for i in range(10):
if self.heartbeat():
self.sessions.remove(session)
break
else:
time.sleep(1)
self.sessions.remove(session)
self.heartbeat_async()
......@@ -126,8 +126,6 @@ class Session:
if len(data) == 0:
msg = "Server close the connection"
logger.info(msg)
for watcher in [self.client] + self._watchers + self._sharers:
watcher.send(msg.encode('utf-8'))
self.close()
break
for watcher in [self.client] + self._watchers + self._sharers:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment