From f9db20e1c4bbecf5a4cafe8cf506df1d8a7322f5 Mon Sep 17 00:00:00 2001 From: Edwin Shepherd Date: Sat, 31 Oct 2026 17:54:34 +0000 Subject: [PATCH 1/2] vision: don't let the postprocessor keep the process alive The thread is only stopped by `Camera.__del__`, but Python waits for non-daemon threads before it destroys objects, so usercode which crashed after creating a `Camera` never exited. Co-Authored-By: Claude Opus 5.5 --- robocon/vision/vision.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/robocon/vision/vision.py b/robocon/vision/vision.py index c6c27be..56621ee 100644 --- a/robocon/vision/vision.py +++ b/robocon/vision/vision.py @@ -324,7 +324,7 @@ def __init__(self, send_to_sheep=False, save=True): - super(PostProcessor, self).__init__() + super(PostProcessor, self).__init__(daemon=True) self._owner = owner self.zone = zone @@ -344,7 +344,9 @@ def __init__(self, def stop(self): """Finish current work then join main process""" self._stop_event.set() - self.join() + # may be called during interpreter shutdown, where daemon threads never + # finish, so don't wait forever + self.join(timeout=2) def stopped(self): """public alias for _stop_event""" From a362485d9e967826eca93e69feead63cdeb0e7d2 Mon Sep 17 00:00:00 2001 From: Edwin Shepherd Date: Sat, 31 Oct 2026 17:54:34 +0000 Subject: [PATCH 2/2] vision: keep the postprocessor alive when a frame fails Any exception ended the thread silently. The queue then filled up, the preview stopped updating and every `C.capture()` blocked for a further second. Co-Authored-By: Claude Opus 5.5 --- robocon/vision/vision.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/robocon/vision/vision.py b/robocon/vision/vision.py index 56621ee..4aa729b 100644 --- a/robocon/vision/vision.py +++ b/robocon/vision/vision.py @@ -411,16 +411,23 @@ def run(self): except queue.Empty: pass else: - frame = capture.colour_frame - if self._bounding_box: - frame = self._draw_bounding_box(frame, detections) - if self._save: - encoded_img = base64.b64encode(cv2.imencode(".jpg", frame)[1]) + b'\n' - self._image_pipe.write(encoded_img) - if self._usb_stick: - self._write_to_usb(capture, detections) - if self._send_to_sheep: - pass + try: + self._process(capture, detections) + except Exception: + logging.exception("Failed to postprocess frame") + + def _process(self, capture, detections): + """Draws on a frame and sends it to wherever it has been configured to go""" + frame = capture.colour_frame + if self._bounding_box: + frame = self._draw_bounding_box(frame, detections) + if self._save: + encoded_img = base64.b64encode(cv2.imencode(".jpg", frame)[1]) + b'\n' + self._image_pipe.write(encoded_img) + if self._usb_stick: + self._write_to_usb(capture, detections) + if self._send_to_sheep: + pass class Vision():