Skip to content

Commit 5c03b4e

Browse files
committed
Make camera validation timer cancellable
Replace QTimer.singleShot with a cancellable QTimer instance (self._camera_validation_timer) that is single-shot, connected to _validate_configured_cameras, and started with a 100ms delay. The closeEvent now stops the timer if it's still active to prevent validation from firing while the window is closing, avoiding modal QMessageBox races/crashes during tests/CI teardown.
1 parent ebfad63 commit 5c03b4e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

dlclivegui/gui/main_window.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,17 @@ def __init__(self, config: ApplicationSettings | None = None):
196196

197197
# Validate cameras from loaded config (deferred to allow window to show first)
198198
# NOTE IMPORTANT (tests/CI): This is scheduled via a QTimer and may fire during pytest-qt teardown.
199-
QTimer.singleShot(100, self._validate_configured_cameras)
199+
# NOTE @C-Achard 2026-03-02: Handling this in closeEvent should help
200+
self._camera_validation_timer = QTimer(self)
201+
self._camera_validation_timer.setSingleShot(True)
202+
self._camera_validation_timer.timeout.connect(self._validate_configured_cameras)
203+
self._camera_validation_timer.start(100)
200204
# If validation triggers a modal QMessageBox (warning/error) while the parent window is closing,
201205
# it can cause errors with unpredictable timing (heap corruption / access violations).
202206
#
203207
# Mitigations for tests/CI:
204208
# - Disable this timer by monkeypatching _validate_configured_cameras in GUI tests
205209
# - OR monkeypatch/override _show_warning/_show_error to no-op in GUI tests (easiest)
206-
# - OR use a cancellable QTimer attribute and stop() it in closeEvent
207210

208211
def resizeEvent(self, event):
209212
super().resizeEvent(event)
@@ -2023,6 +2026,8 @@ def closeEvent(self, event: QCloseEvent) -> None: # pragma: no cover - GUI beha
20232026
if self.multi_camera_controller.is_running():
20242027
self.multi_camera_controller.stop(wait=True)
20252028

2029+
if hasattr(self, "_camera_validation_timer") and self._camera_validation_timer.isActive():
2030+
self._camera_validation_timer.stop()
20262031
# Stop all multi-camera recorders
20272032
self._rec_manager.stop_all()
20282033

0 commit comments

Comments
 (0)