From: Marcel van der Veldt Date: Sun, 27 Dec 2020 14:40:41 +0000 (+0100) Subject: fix process exit X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=eda66859ec01a47eacf1bf54f4b12243c2bbfa5d;p=music-assistant-server.git fix process exit --- diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 7574aa43..5c1f3117 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -1,6 +1,6 @@ """All constants for Music Assistant.""" -__version__ = "0.0.79" +__version__ = "0.0.80" REQUIRED_PYTHON_VER = "3.7" # configuration keys/attributes diff --git a/music_assistant/helpers/process.py b/music_assistant/helpers/process.py index f7d99ee5..e4bafc53 100644 --- a/music_assistant/helpers/process.py +++ b/music_assistant/helpers/process.py @@ -18,7 +18,7 @@ from typing import AsyncGenerator, List, Optional LOGGER = logging.getLogger("AsyncProcess") -DEFAULT_CHUNKSIZE = 1000000 +DEFAULT_CHUNKSIZE = 512000 class AsyncProcess: @@ -48,11 +48,14 @@ class AsyncProcess: async def __aexit__(self, exc_type, exc_value, traceback) -> bool: """Exit context manager.""" self._cancelled = True - if await self.loop.run_in_executor(None, self._proc.poll) is None: + if self._proc.poll() is None: # prevent subprocess deadlocking, send terminate and read remaining bytes - await self.loop.run_in_executor(None, self._proc.terminate) - await self.loop.run_in_executor(None, self.__read) - del self._proc + def close_proc(): + self._proc.terminate() + self._proc.stdin.close() + self._proc.stdout.read(-1) + + await self.loop.run_in_executor(None, close_proc) return exc_type not in (GeneratorExit, asyncio.CancelledError) async def iterate_chunks( diff --git a/music_assistant/managers/streams.py b/music_assistant/managers/streams.py index 23990576..627ed0b1 100755 --- a/music_assistant/managers/streams.py +++ b/music_assistant/managers/streams.py @@ -139,7 +139,8 @@ class StreamManager: fill_buffer_task = self.mass.loop.create_task(fill_buffer()) # start yielding audio chunks - async for chunk in sox_proc.iterate_chunks(8000000): + chunk_size = sample_rate * 4 * 2 * 10 + async for chunk in sox_proc.iterate_chunks(chunk_size): yield chunk await asyncio.wait([fill_buffer_task]) @@ -336,7 +337,7 @@ class StreamManager: # start streaming LOGGER.debug("Start streaming %s (%s)", queue_item_id, queue_item.name) async for _, audio_chunk in self.async_get_sox_stream( - streamdetails, gain_db_adjust=gain_correct, chunk_size=8000000 + streamdetails, gain_db_adjust=gain_correct, chunk_size=4000000 ): yield audio_chunk LOGGER.debug("Finished streaming %s (%s)", queue_item_id, queue_item.name)