fix process exit
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 27 Dec 2020 14:40:41 +0000 (15:40 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 27 Dec 2020 14:40:41 +0000 (15:40 +0100)
music_assistant/constants.py
music_assistant/helpers/process.py
music_assistant/managers/streams.py

index 7574aa438169a3480d140324478a0edac1e470c0..5c1f3117810cd0fa4b489b917f620f947082faed 100755 (executable)
@@ -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
index f7d99ee5d8c7b5b1ba3c11a0519ce5ec13aa3e44..e4bafc539cfaf63dbdbeab8dc5e1c24ec7231129 100644 (file)
@@ -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(
index 23990576ebc42e9c8937945342333b44fc482ede..627ed0b173347a5ad1acc08dbaf0c14bb1cbe243 100755 (executable)
@@ -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)