Skip to content

Commit 76d9a30

Browse files
committed
Force-terminate frozen camera threads on stop
Make multi-camera shutdown more robust by iterating threads with their camera IDs, skipping non-running threads, and quitting each thread. If a thread fails to stop within 5000ms, log an error and call terminate() then wait an additional 1000ms to ensure it stops. Also simplify the start() docstring.
1 parent a4d21f7 commit 76d9a30

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

dlclivegui/services/multi_camera_controller.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def get_active_count(self) -> int:
143143
return len(self._started_cameras)
144144

145145
def start(self, camera_settings: list[CameraSettings]) -> None:
146-
"""Start multiple cameras; accepts dataclasses, pydantic models, or dicts."""
146+
"""Start multiple cameras."""
147147
if self._running:
148148
LOGGER.warning("Multi-camera controller already running")
149149
return
@@ -201,10 +201,15 @@ def stop(self, wait: bool = True) -> None:
201201

202202
# Wait for threads to finish
203203
if wait:
204-
for thread in self._threads.values():
205-
if thread.isRunning():
206-
thread.quit()
207-
thread.wait(5000)
204+
for cam_id, thread in list(self._threads.items()):
205+
if not thread.isRunning():
206+
continue
207+
208+
thread.quit()
209+
if not thread.wait(5000):
210+
LOGGER.error("Frozen camera thread %s; Forcing terminate()", cam_id)
211+
thread.terminate()
212+
thread.wait(1000)
208213

209214
self._workers.clear()
210215
self._threads.clear()

0 commit comments

Comments
 (0)