Skip to content

Commit 4d546f8

Browse files
committed
fix: graceful SIGTERM shutdown — exit(0) instead of flag
The stdin read loop blocks on sys.stdin, so the old running=False flag approach never took effect. The process would hang until forcibly killed (exit code null), triggering Aegis auto-diagnostics unnecessarily. Now the signal handler emits final perf stats and calls sys.exit(0) directly for a clean shutdown.
1 parent 27895cc commit 4d546f8

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • skills/detection/yolo-detection-2026/scripts

skills/detection/yolo-detection-2026/scripts/detect.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,18 +268,19 @@ def main():
268268
emit({"event": "error", "message": f"Failed to load model: {e}", "retriable": False})
269269
sys.exit(1)
270270

271-
# Graceful shutdown
272-
running = True
271+
# Graceful shutdown — exit immediately with code 0.
272+
# The stdin read loop blocks, so setting a flag doesn't work;
273+
# we must exit in the signal handler to avoid being killed (code null).
273274
def handle_signal(signum, frame):
274-
nonlocal running
275-
running = False
275+
sig_name = "SIGTERM" if signum == signal.SIGTERM else "SIGINT"
276+
log(f"Received {sig_name}, shutting down gracefully")
277+
perf.emit_final()
278+
sys.exit(0)
276279
signal.signal(signal.SIGTERM, handle_signal)
277280
signal.signal(signal.SIGINT, handle_signal)
278281

279282
# Main loop: read frames from stdin, output detections to stdout
280283
for line in sys.stdin:
281-
if not running:
282-
break
283284

284285
line = line.strip()
285286
if not line:

0 commit comments

Comments
 (0)