fix cpu usage
authormarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Sat, 19 Oct 2019 19:18:15 +0000 (21:18 +0200)
committermarcelveldt <marcelvanderveldt@MacBook-Silvia.local>
Sat, 19 Oct 2019 19:18:15 +0000 (21:18 +0200)
music_assistant/__init__.py
music_assistant/homeassistant.py
music_assistant/http_streamer.py

index 6be460e7075453cec90be059f0492e5efd6da01c..8cc2b00c1242c1084c9084d6ec38cfc66c214bac 100644 (file)
@@ -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
index 018c4538477062b483302e30e3272245fac6bdb6..8fd99bc2806f675c0e21ecaebf802b9b2e963371 100644 (file)
@@ -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'''
index fefc97a93731ea68fe7e80b353d79edbd05c60d5..a5df76ef8ae22d0920891a27d3a5523091df0ad3 100755 (executable)
@@ -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