cleanup
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 12 Apr 2024 09:08:25 +0000 (11:08 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 12 Apr 2024 09:08:25 +0000 (11:08 +0200)
music_assistant/server/helpers/audio.py

index 8dfa838ff0ca884bf9b9e017c94043c0f9bb73a5..648cb3d176d7438b2776aa6a8b9848789c37a2d4 100644 (file)
@@ -143,11 +143,12 @@ class FFMpeg(AsyncProcess):
             self.proc.stdin.close()
             await asyncio.sleep(0)  # yield to loop
         # abort existing readers on stdout first before we send communicate
-        if self.proc.stdout:
-            if self.proc.stdout._waiter is not None:
-                with suppress(asyncio.exceptions.InvalidStateError):
-                    self.proc.stdout._waiter.set_exception(asyncio.CancelledError())
-            # read reamaing bytes to unblock pipe
+        waiter: asyncio.Future
+        if self.proc.stdout and (waiter := self.proc.stdout._waiter):
+            self.proc.stdout._waiter = None
+            if waiter and not waiter.done():
+                waiter.set_exception(asyncio.CancelledError())
+            # read remaining bytes to unblock pipe
             await self.read(-1)
         # wait for log task to complete that reads the remaining data from stderr
         with suppress(TimeoutError):