From 9c3412fd46f872ebff6960cfcfde435413ab34ad Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Mon, 11 Apr 2022 10:55:35 +0200 Subject: [PATCH] Fix BrokenPipe error (#254) --- music_assistant/helpers/process.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/music_assistant/helpers/process.py b/music_assistant/helpers/process.py index 2f5b09a3..f0f2ea20 100644 --- a/music_assistant/helpers/process.py +++ b/music_assistant/helpers/process.py @@ -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.""" -- 2.34.1