Skip to content

Commit b951a01

Browse files
committed
Retry recorder stop until success
Make recording shutdown more robust by retrying `stop_all()` in both async stop and app close paths with a configurable interval (`RECORD_STOP_RETRY_INTERVAL`). Also disable recording frame emission before shutdown stop attempts and log stop/shutdown errors for better diagnostics.
1 parent e59ad7e commit b951a01

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎dlclivegui/config.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
DEFAULT_RECORDING_FPS: float = 30.0
2828
ALLOWED_VIDEO_CONTAINERS: set[str] = {"mp4", "avi", "mov"}
2929
DEFAULT_RECORDING_CONTAINER: str = "mp4"
30+
RECORD_STOP_RETRY_INTERVAL: float = 0.25
3031

3132

3233
## Debug

‎dlclivegui/gui/main_window.py‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
DEFAULT_RECORDING_CONTAINER,
5555
DLC_DO_LOG_TIMING,
5656
GUI_MAX_DISPLAY_FPS,
57+
RECORD_STOP_RETRY_INTERVAL,
5758
ApplicationSettings,
5859
BoundingBoxSettings,
5960
CameraSettings,
@@ -1652,9 +1653,14 @@ def _stop_multi_camera_recording(self) -> None:
16521653

16531654
def worker():
16541655
try:
1655-
self._rec_manager.stop_all()
1656-
finally:
1657-
self._recording_stopped_async.emit()
1656+
while not self._rec_manager.stop_all():
1657+
logger.info("Retrying recorder stop...")
1658+
time.sleep(RECORD_STOP_RETRY_INTERVAL)
1659+
except Exception as e:
1660+
logger.exception("Error while stopping recording: %s", e)
1661+
return
1662+
1663+
self._recording_stopped_async.emit()
16581664

16591665
threading.Thread(
16601666
target=worker,
@@ -2261,7 +2267,13 @@ def closeEvent(self, event: QCloseEvent) -> None: # pragma: no cover - GUI beha
22612267
if hasattr(self, "_camera_validation_timer") and self._camera_validation_timer.isActive():
22622268
self._camera_validation_timer.stop()
22632269
# Stop all multi-camera recorders
2264-
self._rec_manager.stop_all()
2270+
try:
2271+
self.multi_camera_controller.set_recording_frame_do_emit(False)
2272+
except Exception:
2273+
logger.exception("Failed to disable recording frame emission during shutdown")
2274+
while not self._rec_manager.stop_all():
2275+
logger.info("Retrying recorder stop during shutdown...")
2276+
time.sleep(RECORD_STOP_RETRY_INTERVAL)
22652277

22662278
# Close the camera dialog if open (ensures its worker thread is canceled)
22672279
if getattr(self, "_cam_dialog", None) is not None and self._cam_dialog.isVisible():

0 commit comments

Comments
 (0)