From e58f5d2fa1a9d6e087a6e895d08f0fd0d9761a40 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 26 Feb 2024 01:26:03 +0100 Subject: [PATCH] [Camera] The `wait_for_either` barrier should be enabled on streaming by default. `camera.pi*` plugins are an exception, as they handle the lifecycle of the camera streaming process through the `picamera*` libraries. Otherwise, the streaming thread should explicitly wait on either the plugin stop or streaming stop events and exit accordingly, or the camera thread may be streaming indefinitely. --- platypush/plugins/camera/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platypush/plugins/camera/__init__.py b/platypush/plugins/camera/__init__.py index a51a891bc..059b5855b 100644 --- a/platypush/plugins/camera/__init__.py +++ b/platypush/plugins/camera/__init__.py @@ -770,6 +770,12 @@ class CameraPlugin(RunnablePlugin, ABC): self.logger.info('Stopped camera stream') + def _wait_stream_stop(self, camera: Camera): + try: + wait_for_either(self._should_stop, camera.stop_stream_event) + except Exception as e: + self.logger.debug('Error on streaming poll: %s', e) + def _streaming_loop( self, camera: Camera, @@ -785,6 +791,7 @@ class CameraPlugin(RunnablePlugin, ABC): assert camera.stream, 'No camera stream available' camera.stream.sock = sock self.start_camera(camera, duration=duration, frames_dir=None, image_file=None) + self._wait_stream_stop(camera) def _cleanup_stream( self, camera: Camera, server_socket: socket.socket, client: Optional[IO]