Fix: prevent high cpu when filling cache
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 7 Mar 2025 23:55:24 +0000 (00:55 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 7 Mar 2025 23:55:24 +0000 (00:55 +0100)
yield to eventloop to allow headroom for other tasks to be executed

music_assistant/helpers/audio.py

index a6aea7603294a737c9e22c108ff398e68a74c8c6..d71b4fdd7199bbeb8c32c28e215bb021f675a8da 100644 (file)
@@ -116,6 +116,7 @@ class StreamCache:
                 else:
                     yield chunk
                 del chunk
+                await asyncio.sleep(0)  # yield to eventloop
         finally:
             self._subscribers -= 1
             if self._subscribers == 0:
@@ -157,10 +158,12 @@ class StreamCache:
             input_format=self.streamdetails.audio_format,
             output_format=self.streamdetails.audio_format,
             extra_input_args=extra_input_args,
+            chunk_size=64000,
         ):
             async with self._lock:
                 self._data += chunk
                 del chunk
+                await asyncio.sleep(0)  # yield to eventloop
             if not self._first_part_received.is_set():
                 self._first_part_received.set()
                 self.logger.debug(