From 1c72823dd5dde02d66ce6d3433a409a8d35647ed Mon Sep 17 00:00:00 2001 From: Stefan Bethke Date: Sat, 23 Dec 2023 09:16:46 +0100 Subject: [PATCH] Send WS updates on threads Hopefully that means that clients that are blocking do not hold up the entire process. --- mumblestats.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mumblestats.py b/mumblestats.py index 4ff4970..5d48819 100644 --- a/mumblestats.py +++ b/mumblestats.py @@ -146,14 +146,19 @@ def collect_stats(self): while self.running: for channel in self.channels: if not self.stats[channel].is_alive(): - print('{} is not alive anymore'.format(channel)) + #print('{} is not alive anymore'.format(channel)) return self.stats[channel].update_stats() stats = self.get_stats() self.update_prometheus_metrics(stats) wsjson = json.dumps(stats) for ws in self.wsstats_clients: - ws.send(wsjson) + def send(): + try: + ws.send(wsjson) + except Exception: + self.wsstats_clients.remove(ws) + t = threading.Thread(target=send, daemon=True).start() time.sleep(.1) for channel in self.channels: self.mumble_close(self.stats[channel])