Skip to content

Commit 6cdadf3

Browse files
author
Dylan Huang
committed
TODO: TestLogsServer
1 parent 2e0be24 commit 6cdadf3

2 files changed

Lines changed: 516 additions & 6 deletions

File tree

eval_protocol/utils/logs_server.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,32 @@ async def _send_text_to_all_connections(self, text: str):
8787
return
8888

8989
tasks = []
90+
failed_connections = []
91+
9092
for connection in connections:
9193
try:
9294
tasks.append(connection.send_text(text))
9395
except Exception as e:
9496
logger.error(f"Failed to send text to WebSocket: {e}")
95-
with self._lock:
96-
try:
97-
self.active_connections.remove(connection)
98-
except ValueError:
99-
pass
97+
failed_connections.append(connection)
98+
99+
# Execute all sends in parallel
100100
if tasks:
101-
await asyncio.gather(*tasks, return_exceptions=True)
101+
results = await asyncio.gather(*tasks, return_exceptions=True)
102+
103+
# Check for any exceptions that occurred during execution
104+
for i, result in enumerate(results):
105+
if isinstance(result, Exception):
106+
logger.error(f"Failed to send text to WebSocket: {result}")
107+
failed_connections.append(connections[i])
108+
109+
# Remove all failed connections
110+
with self._lock:
111+
for connection in failed_connections:
112+
try:
113+
self.active_connections.remove(connection)
114+
except ValueError:
115+
pass
102116

103117
def start_broadcast_loop(self):
104118
"""Start the broadcast loop in the current event loop."""

0 commit comments

Comments
 (0)