Continuously read messages and dispatch them.
(self)
| 194 | # ── Background reader ──────────────────────────────────────────── |
| 195 | |
| 196 | def _reader_loop(self) -> None: |
| 197 | """Continuously read messages and dispatch them.""" |
| 198 | try: |
| 199 | while not self._stopped: |
| 200 | try: |
| 201 | msg = _read_message(self._proc.stdout) |
| 202 | except EOFError: |
| 203 | break |
| 204 | |
| 205 | # Is this a response to one of our requests? |
| 206 | if "id" in msg and "method" not in msg: |
| 207 | rid = msg["id"] |
| 208 | with self._pending_lock: |
| 209 | q = self._pending.get(rid) |
| 210 | if q is not None: |
| 211 | q.put(msg) |
| 212 | continue |
| 213 | |
| 214 | # Is this a server-to-client request that needs a reply? |
| 215 | method = msg.get("method", "") |
| 216 | if method in self._SERVER_REQUESTS and "id" in msg: |
| 217 | self._send_raw({ |
| 218 | "jsonrpc": "2.0", |
| 219 | "id": msg["id"], |
| 220 | "result": None, |
| 221 | }) |
| 222 | # Also forward as a notification so callers can |
| 223 | # observe it (e.g. progress token creation). |
| 224 | self._notifications.put(msg) |
| 225 | continue |
| 226 | |
| 227 | # Everything else is a notification. |
| 228 | self._notifications.put(msg) |
| 229 | except Exception as exc: |
| 230 | self._reader_error = exc |
| 231 | |
| 232 | # ── Transport ──────────────────────────────────────────────────── |
| 233 |
nothing calls this directly
no test coverage detected