Read exactly num_bytes, handling partial/short reads from pipes. Args: num_bytes: Number of bytes to read Returns: Bytes read from stream Raises: EOFError: If stream ends before reading all bytes
(self, num_bytes: int)
| 304 | loop.call_soon_threadsafe(future.set_exception, exc) |
| 305 | |
| 306 | def _read_exact(self, num_bytes: int) -> bytes: |
| 307 | """ |
| 308 | Read exactly num_bytes, handling partial/short reads from pipes. |
| 309 | |
| 310 | Args: |
| 311 | num_bytes: Number of bytes to read |
| 312 | |
| 313 | Returns: |
| 314 | Bytes read from stream |
| 315 | |
| 316 | Raises: |
| 317 | EOFError: If stream ends before reading all bytes |
| 318 | """ |
| 319 | chunks = [] |
| 320 | remaining = num_bytes |
| 321 | while remaining > 0: |
| 322 | chunk = self.process.stdout.read(remaining) |
| 323 | if not chunk: |
| 324 | raise EOFError("Unexpected end of stream while reading JSON-RPC message") |
| 325 | chunks.append(chunk) |
| 326 | remaining -= len(chunk) |
| 327 | return b"".join(chunks) |
| 328 | |
| 329 | def _read_message(self) -> dict | None: |
| 330 | """ |