Skip to content

Commit f608361

Browse files
committed
Improve scan worker cleanup and error logging
Replace a bare exception handler when installing event filters with specific (AttributeError, RuntimeError) handling and log a warning so failures are not silently swallowed. Enhance _on_scan_thread_finished to ignore finished signals from stale workers, attempt deleteLater() on old senders, and only transition the active worker to IDLE to avoid race conditions affecting scan state.
1 parent 05cff1e commit f608361

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

dlclivegui/gui/camera_config/camera_config_dialog.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,8 @@ def _setup_ui(self) -> None:
277277
le = sb.lineEdit()
278278
if le is not None:
279279
le.installEventFilter(self)
280-
except Exception:
281-
pass
280+
except (AttributeError, RuntimeError) as exc:
281+
LOGGER.warning("Failed to install event filter on %s: %s", sb.objectName(), exc)
282282

283283
def _position_scan_overlay(self) -> None:
284284
"""Position scan overlay to cover the available_cameras_list area."""
@@ -624,9 +624,22 @@ def _on_scan_progress(self, msg: str) -> None:
624624
return
625625
self._show_scan_overlay(msg or "Discovering cameras…")
626626

627-
def _on_scan_thread_finished(self):
627+
def _on_scan_thread_finished(self) -> None:
628+
sender = self.sender()
629+
# Ignore finished signals from old workers; only clean up the active one.
630+
if sender is not None and sender is not self._scan_worker:
631+
LOGGER.debug("[Scan] Ignoring finished from old worker")
632+
# Make sure the old worker can be cleaned up by Qt.
633+
try:
634+
sender.deleteLater()
635+
except AttributeError:
636+
pass
637+
return
638+
628639
self._cleanup_scan_worker()
629-
self._set_scan_state(CameraScanState.IDLE)
640+
# Only transition to IDLE for the worker that was actually active.
641+
if self._scan_state not in (CameraScanState.DONE,):
642+
self._set_scan_state(CameraScanState.IDLE)
630643

631644
def _on_scan_result(self, cams: list) -> None:
632645
if self.sender() is not self._scan_worker:

0 commit comments

Comments
 (0)