From eddf37c413667dc46b32d6845b33522ba6ae361f Mon Sep 17 00:00:00 2001 From: cppla <i@cpp.la> Date: Tue, 23 Jan 2024 10:30:43 +0800 Subject: [PATCH] fix bug --- clients/client-linux.py | 17 ++++++++++------- clients/client-psutil.py | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/clients/client-linux.py b/clients/client-linux.py index 5a6bd1c..fc65827 100755 --- a/clients/client-linux.py +++ b/clients/client-linux.py @@ -324,13 +324,7 @@ def _monitor_thread(name, host, interval, type): packet_queue = Queue(maxsize=ONLINE_PACKET_HISTORY_LEN) while True: if name not in monitorServer.keys(): - monitorServer[name] = { - "type": type, - "dns_time": 0, - "connect_time": 0, - "download_time": 0, - "online_rate": 1 - } + break if packet_queue.full(): if packet_queue.get() == 0: lostPacket -= 1 @@ -459,6 +453,13 @@ if __name__ == '__main__': for i in data.split('\n'): if "monitor" in i and "type" in i and "{" in i and "}" in i: jdata = json.loads(i[i.find("{"):i.find("}")+1]) + monitorServer[jdata.get("name")] = { + "type": jdata.get("type"), + "dns_time": 0, + "connect_time": 0, + "download_time": 0, + "online_rate": 1 + } t = threading.Thread( target=_monitor_thread, kwargs={ @@ -524,11 +525,13 @@ if __name__ == '__main__': except KeyboardInterrupt: raise except socket.error: + monitorServer.clear() print("Disconnected...") if 's' in locals().keys(): del s time.sleep(3) except Exception as e: + monitorServer.clear() print("Caught Exception:", e) if 's' in locals().keys(): del s diff --git a/clients/client-psutil.py b/clients/client-psutil.py index da871b8..bcb8ea0 100755 --- a/clients/client-psutil.py +++ b/clients/client-psutil.py @@ -312,13 +312,7 @@ def _monitor_thread(name, host, interval, type): packet_queue = Queue(maxsize=ONLINE_PACKET_HISTORY_LEN) while True: if name not in monitorServer.keys(): - monitorServer[name] = { - "type": type, - "dns_time": 0, - "connect_time": 0, - "download_time": 0, - "online_rate": 1 - } + break if packet_queue.full(): if packet_queue.get() == 0: lostPacket -= 1 @@ -444,10 +438,16 @@ if __name__ == '__main__': if data.find("You are connecting via") < 0: data = byte_str(s.recv(1024)) print(data) - monitorServer.clear() for i in data.split('\n'): if "monitor" in i and "type" in i and "{" in i and "}" in i: jdata = json.loads(i[i.find("{"):i.find("}")+1]) + monitorServer[jdata.get("name")] = { + "type": jdata.get("type"), + "dns_time": 0, + "connect_time": 0, + "download_time": 0, + "online_rate": 1 + } t = threading.Thread( target=_monitor_thread, kwargs={ @@ -514,11 +514,13 @@ if __name__ == '__main__': except KeyboardInterrupt: raise except socket.error: + monitorServer.clear() print("Disconnected...") if 's' in locals().keys(): del s time.sleep(3) except Exception as e: + monitorServer.clear() print("Caught Exception:", e) if 's' in locals().keys(): del s