Quellcode durchsuchen

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.
Chinesezjc vor 1 Monat
Ursprung
Commit
2d82b658ba
1 geänderte Dateien mit 6 neuen und 0 gelöschten Zeilen
  1. 6 0
      packages/code-runtime/code-runtime-python/py/bootstrap.py

+ 6 - 0
packages/code-runtime/code-runtime-python/py/bootstrap.py

@@ -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