Skip to content

Commit 5ec6266

Browse files
committed
Cache _queue to local variable in VideoRecorder
Cache self._queue to a local variable (q) and use it for subsequent operations to avoid races and repeated attribute access. Remove the redundant assert and simplify qsize lookup by relying on the cached reference. This makes queue checks and put/qsize calls consistent in a multithreaded context and prevents potential None/attribute changes between checks and use.
1 parent b4e57d6 commit 5ec6266

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

dlclivegui/services/video_recorder.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def write(self, frame: np.ndarray, timestamp: float | None = None) -> bool:
149149
error = self._current_error()
150150
if error is not None:
151151
raise RuntimeError(f"Video encoding failed: {error}") from error
152-
if not self.is_running or self._queue is None:
152+
153+
q = self._queue
154+
if not self.is_running or q is None:
153155
return False
154156
if self._stop_event.is_set():
155157
return False
@@ -192,12 +194,11 @@ def write(self, frame: np.ndarray, timestamp: float | None = None) -> bool:
192194
return False
193195

194196
try:
195-
assert self._queue is not None
196-
self._queue.put((frame, timestamp), block=False)
197+
q.put((frame, timestamp), block=False)
197198
except queue.Full:
198199
with self._stats_lock:
199200
self._dropped_frames += 1
200-
queue_size = self._queue.qsize() if self._queue is not None else -1
201+
queue_size = q.qsize()
201202
logger.warning(
202203
"Video recorder queue full; dropping frame. queue=%d buffer=%d",
203204
queue_size,

0 commit comments

Comments
 (0)