Fix BrokenPipe error (#254)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Mon, 11 Apr 2022 08:55:35 +0000 (10:55 +0200)
committerGitHub <noreply@github.com>
Mon, 11 Apr 2022 08:55:35 +0000 (10:55 +0200)
music_assistant/helpers/process.py

index 2f5b09a3aa39bf6fcc3c67451e531c08c0194f18..f0f2ea201a55c6ff1450ad742bb549a046a467c5 100644 (file)
@@ -101,13 +101,18 @@ class AsyncProcess:
         try:
             self._proc.stdin.write(data)
             await self._proc.stdin.drain()
-        except (AttributeError, AssertionError, BrokenPipeError) as err:
-            raise asyncio.CancelledError() from err
+        except (AttributeError, AssertionError, BrokenPipeError):
+            # already exited, race condition
+            pass
 
     def write_eof(self) -> None:
         """Write end of file to to process stdin."""
-        if self._proc.stdin.can_write_eof():
-            self._proc.stdin.write_eof()
+        try:
+            if self._proc.stdin.can_write_eof():
+                self._proc.stdin.write_eof()
+        except (AttributeError, AssertionError, BrokenPipeError):
+            # already exited, race condition
+            pass
 
     async def communicate(self, input_data: Optional[bytes] = None) -> bytes:
         """Write bytes to process and read back results."""