From: marcelveldt Date: Sat, 19 Oct 2019 19:18:15 +0000 (+0200) Subject: fix cpu usage X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=d3e69e8c2f581b03ce62221639cfceef04415630;p=music-assistant-server.git fix cpu usage --- diff --git a/music_assistant/__init__.py b/music_assistant/__init__.py index 6be460e7..8cc2b00c 100644 --- a/music_assistant/__init__.py +++ b/music_assistant/__init__.py @@ -57,10 +57,6 @@ class MusicAssistant(): await self.players.setup() await self.web.setup() await self.http_streamer.setup() - # temp code to chase memory leak - import subprocess - subprocess.call("pip install mem_top", shell=True) - self.event_loop.create_task(self.print_memory()) def handle_exception(self, loop, context): ''' global exception handler ''' @@ -83,10 +79,4 @@ class MusicAssistant(): async def remove_event_listener(self, cb_id): ''' remove callback from our event listeners ''' - self.event_listeners.pop(cb_id, None) - - @run_periodic(60) - # TEMP: Check for any memory leaks - async def print_memory(self): - from mem_top import mem_top - print(mem_top()) + self.event_listeners.pop(cb_id, None) \ No newline at end of file diff --git a/music_assistant/homeassistant.py b/music_assistant/homeassistant.py index 018c4538..8fd99bc2 100644 --- a/music_assistant/homeassistant.py +++ b/music_assistant/homeassistant.py @@ -249,7 +249,7 @@ class HomeAssistant(): while self.mass.event_loop.is_running(): try: protocol = 'wss' if self._use_ssl else 'ws' - async with self.http_session.ws_connect('%s://%s/api/websocket' % (protocol, self._host)) as ws: + async with self.http_session.ws_connect('%s://%s/api/websocket' % (protocol, self._host), verify_ssl=False) as ws: async def send_msg(msg): ''' callback to send message to the websockets client''' diff --git a/music_assistant/http_streamer.py b/music_assistant/http_streamer.py index fefc97a9..a5df76ef 100755 --- a/music_assistant/http_streamer.py +++ b/music_assistant/http_streamer.py @@ -135,8 +135,10 @@ class HTTPStreamer(): def fill_buffer(): chunk_size = int(sample_rate * 4 * 2) - while sox_proc.returncode == None: + while True: chunk = sox_proc.stdout.read(chunk_size) + if not chunk: + break if chunk and not cancelled.is_set(): asyncio.run_coroutine_threadsafe( buffer.put(chunk), self.mass.event_loop) @@ -337,7 +339,7 @@ class HTTPStreamer(): data = process.stdout.read(chunksize) if not data: # no more data - # yield (empty) chunk as lust chunk + # yield leftover data in buffer as last chunk yield (True, buf) bytes_sent += len(buf) del buf