Add some additional guards to asyncprocess
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 22 Feb 2026 01:19:59 +0000 (02:19 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 22 Feb 2026 01:19:59 +0000 (02:19 +0100)
music_assistant/helpers/process.py

index 1da3541f2baf954935cc16ff570c97eb54d318a9..090df1ee611a0e560e9d2dc425128e429537d768 100644 (file)
@@ -171,10 +171,10 @@ class AsyncProcess:
 
     async def write(self, data: bytes) -> None:
         """Write data to process stdin."""
-        if self._close_called:
+        if self._close_called or self.proc is None:
+            return
+        if self.proc.stdin is None:
             return
-        assert self.proc is not None  # for type checking
-        assert self.proc.stdin is not None  # for type checking
         async with self._stdin_lock:
             self.proc.stdin.write(data)
             with suppress(BrokenPipeError, ConnectionResetError):
@@ -182,10 +182,10 @@ class AsyncProcess:
 
     async def write_eof(self) -> None:
         """Write end of file to to process stdin."""
-        if self._close_called:
+        if self._close_called or self.proc is None:
+            return
+        if self.proc.stdin is None:
             return
-        assert self.proc is not None  # for type checking
-        assert self.proc.stdin is not None  # for type checking
         async with self._stdin_lock:
             try:
                 if self.proc.stdin.can_write_eof():