Skip to content

Commit 0e75131

Browse files
authored
fix(handlers): avoid "Set changed size during iteration" in monitor loop (#57)
Iterate over list(connections) when broadcasting so the set is not modified during iteration when a client disconnects. Co-authored-by: Panos <>
1 parent ecf2606 commit 0e75131

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

core/handlers.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,14 @@ async def monitor_loop(monitor, connections):
117117
'system': system_info
118118
}
119119

120-
# Send to all connected clients
120+
# Send to all connected clients (iterate over copy to avoid "Set changed size during iteration")
121121
if connections:
122122
disconnected = set()
123-
for websocket in connections:
123+
for websocket in list(connections):
124124
try:
125125
await websocket.send_text(json.dumps(data))
126-
except:
126+
except Exception:
127127
disconnected.add(websocket)
128-
129-
# Remove disconnected clients
130128
connections -= disconnected
131129

132130
except Exception as e:

static/css/components.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,24 @@
434434

435435
.sparkline-canvas-wrap {
436436
height: 90px;
437+
min-height: 90px;
438+
max-height: 90px;
437439
position: relative;
438440
overflow: hidden;
439441
}
440442

443+
/* Constrain Chart.js wrapper and canvas so they cannot grow (fixes canvas height runaway) */
444+
.sparkline-canvas-wrap > div {
445+
height: 100% !important;
446+
max-height: 90px !important;
447+
min-height: 0;
448+
}
449+
441450
.sparkline-canvas-wrap canvas {
442451
display: block !important;
443452
width: 100% !important;
444453
height: 100% !important;
454+
max-height: 90px !important;
445455
}
446456

447457
/* ============================================

static/js/chart-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function initGPUCharts(gpuId) {
274274

275275
const ctx = canvas.getContext('2d');
276276
const rect = canvas.parentElement.getBoundingClientRect();
277-
const h = rect.height || 120;
277+
const h = (rect.height > 0 ? rect.height : 90);
278278
const gradient = ctx.createLinearGradient(0, 0, 0, h);
279279
gradient.addColorStop(0, 'rgba(255, 255, 255, 0.06)');
280280
gradient.addColorStop(1, 'rgba(255, 255, 255, 0.0)');

version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""Version information for GPU Hot"""
22

3-
__version__ = "1.7.1"
3+
__version__ = "1.7.2"
44

0 commit comments

Comments
 (0)