Commit 16d758ec authored by ibuler's avatar ibuler

[Update] 更新debug

parent b3693eca
......@@ -9,6 +9,8 @@ import threading
import socket
import json
import signal
import objgraph
import gc
from jms.service import AppService
......@@ -132,6 +134,7 @@ class Coco:
def heartbeat(self):
_sessions = [s.to_json() for s in self.sessions]
tasks = self.service.terminal_heartbeat(_sessions)
gc.collect()
if tasks:
self.handle_task(tasks)
if tasks is False:
......@@ -219,13 +222,19 @@ class Coco:
def add_client(self, client):
with self.lock:
self.clients.append(client)
logger.info("New client {} join, total {} now".format(client, len(self.clients)))
logger.info("New client {} join, total {} now".format(
client, len(self.clients)
)
)
def remove_client(self, client):
with self.lock:
try:
self.clients.remove(client)
logger.info("Client {} leave, total {} now".format(client, len(self.clients)))
logger.info("Client {} leave, total {} now".format(
client, len(self.clients)
)
)
client.close()
except:
pass
......@@ -242,4 +251,5 @@ class Coco:
self.sessions.remove(session)
self.service.finish_session(session.to_json())
except ValueError:
logger.warning("Remove session: {} fail, maybe already removed".format(session))
\ No newline at end of file
msg = "Remove session: {} fail, maybe already removed"
logger.warning(msg.format(session))
......@@ -212,8 +212,7 @@ class ProxyNamespace(BaseNamespace):
def on_disconnect(self):
logger.debug("On disconnect event trigger")
room_id_list = list(self.connections.get(request.sid, {}).keys())
for room_id in room_id_list:
for room_id in self.connections.get(request.sid, {}):
try:
self.on_logout(room_id)
except Exception as e:
......@@ -250,14 +249,14 @@ class HttpServer:
self.flask_app.config.update(config)
self.socket_io = SocketIO()
self.register_routes()
self.register_error_handler()
def register_routes(self):
self.socket_io.on_namespace(ProxyNamespace('/ssh'))
@staticmethod
def on_error_default(e):
traceback.print_exc()
logger.warn(e)
logger.exception(e)
def register_error_handler(self):
self.socket_io.on_error_default(self.on_error_default)
......
......@@ -251,7 +251,6 @@ class WSProxy:
if len(data) == 0:
self.close()
data = data.decode(errors="ignore")
print("Send data: {}".format(data))
self.ws.emit("data", {'data': data, 'room': self.room_id},
room=self.room_id)
if len(data) == BUF_SIZE:
......
......@@ -396,7 +396,6 @@ def size_of_str_with_zh(s):
try:
chinese = find_chinese(s)
except TypeError:
print(type(s))
raise
return len(s) + len(chinese)
......
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