fix(code-runtime-python): bind RuntimeError inside the module-level _pump_replies

The previous commit bound _RuntimeError in _run, but _pump_replies is a separate
module-level function, so its except _RuntimeError referenced an out-of-scope
local and raised NameError instead of catching the closed-loop failure — killing
the pump and timing out the run. Bind _RuntimeError at the top of _pump_replies
too. The closed-loop pump test now passes.
This commit is contained in:
Chinesezjc
2026-08-31 14:34:09 +08:00
committed by Tianyi Cui
parent bcc11f1235
commit 2d82b658ba
@@ -1122,6 +1122,12 @@ async def _pump_replies(
pending: dict[int, tuple[asyncio.AbstractEventLoop, asyncio.Future[Any]]],
pending_lock: "threading.Lock",
) -> None:
# The exception class the closed-loop catch below resolves is bound into a
# LOCAL here. This bootstrap IS `__main__`, so `__main__.RuntimeError = ...`
# would otherwise rebind the module global the `except RuntimeError` clause
# resolves at runtime, and a closed-loop scheduling failure would then escape
# the catch, killing the pump and stranding every later reply.
_RuntimeError = RuntimeError
"""Background task: read reply frames and settle pending futures.
Cancelled after ``done`` is posted. Unknown ids and post-settlement replies