Block until the response for *request_id* arrives.
(
self, request_id: int, timeout: float = 30
)
| 267 | }) |
| 268 | |
| 269 | def wait_for_response( |
| 270 | self, request_id: int, timeout: float = 30 |
| 271 | ) -> dict[str, Any]: |
| 272 | """Block until the response for *request_id* arrives.""" |
| 273 | with self._pending_lock: |
| 274 | q = self._pending.get(request_id) |
| 275 | if q is None: |
| 276 | raise ValueError(f"Unknown request id {request_id}") |
| 277 | try: |
| 278 | msg = q.get(timeout=timeout) |
| 279 | except queue.Empty: |
| 280 | raise TimeoutError( |
| 281 | f"No response for request {request_id} within {timeout}s" |
| 282 | ) from None |
| 283 | finally: |
| 284 | with self._pending_lock: |
| 285 | self._pending.pop(request_id, None) |
| 286 | return msg |
| 287 | |
| 288 | # ── High-level protocol ────────────────────────────────────────── |
| 289 |
no test coverage detected