diff --git a/displayarray/frame/frame_updater.py b/displayarray/frame/frame_updater.py index b76d68a..4cd79a1 100644 --- a/displayarray/frame/frame_updater.py +++ b/displayarray/frame/frame_updater.py @@ -91,14 +91,18 @@ class FrameUpdater(threading.Thread): sub_cam = subscriber_dictionary.cam_frame_sub(str(self.cam_id)) sub_owner = subscriber_dictionary.handler_cmd_sub(str(self.cam_id)) msg_owner = sub_owner.return_on_no_data = "" - while msg_owner != "quit": - frame = sub_cam.get(blocking=True, timeout=1.0) # type: np.ndarray - self.__apply_callbacks_to_frame(frame) - msg_owner = sub_owner.get() - sub_owner.release() - sub_cam.release() - subscriber_dictionary.stop_cam(self.cam_id) - t.join() + try: + while msg_owner != "quit": + frame = sub_cam.get(blocking=True, timeout=1.0) # type: np.ndarray + self.__apply_callbacks_to_frame(frame) + msg_owner = sub_owner.get() + except Exception as e: + raise e + finally: + sub_owner.release() + sub_cam.release() + subscriber_dictionary.stop_cam(self.cam_id) + t.join() def display(self, callbacks: List[Callable[[np.ndarray], Any]] = None): """ diff --git a/tests/frame/test_frame_updater.py b/tests/frame/test_frame_updater.py index 3230511..1fe291e 100644 --- a/tests/frame/test_frame_updater.py +++ b/tests/frame/test_frame_updater.py @@ -75,7 +75,7 @@ def test_callback_exception(): frame[:, :, 2] = 1 / 0 with pytest.raises(ZeroDivisionError) as e: - v = fup.FrameUpdater(np.zeros((1, 1, 3)), callbacks=redden_frame_print_spam) + v = fup.FrameUpdater(np.zeros((1, 2, 3)), callbacks=redden_frame_print_spam) v.loop() assert e.errisinstance(ZeroDivisionError) @@ -92,8 +92,6 @@ def test_display(): mock_sub_win.assert_called_once_with(video_sources=["0"], callbacks=[]) mock_sub_win_instance.loop.assert_called_once() - f.start.assert_called_once() - f.join.assert_called_once() def test_display_exception(): @@ -109,6 +107,7 @@ def test_display_exception(): v = fup.FrameUpdater(np.zeros((1, 1, 3)), callbacks=redden_frame_print_spam) v.display() assert e.errisinstance(ZeroDivisionError) + # todo: clear the frame dict so that these don't hang forever from displayarray.window.window_commands import win_cmd_pub