front: fix SyntaxError in _counting_iter (bare try without except/finally)

The previous commit (be9950a5) left a try: with no except/finally in the SSE
throughput counter, breaking import of the front. Remove the stray try (the
BackgroundTask _release already closes the upstream response).
Co-Authored-By: 's avatarClaude Opus 4.8 <noreply@anthropic.com>
parent be9950a5
...@@ -724,19 +724,17 @@ class FrontProxy: ...@@ -724,19 +724,17 @@ class FrontProxy:
async def _counting_iter(): async def _counting_iter():
import time as _t import time as _t
t0 = _t.monotonic(); ntok = 0; last = 0.0 t0 = _t.monotonic(); ntok = 0; last = 0.0
try: async for raw in rp_resp.aiter_raw():
async for raw in rp_resp.aiter_raw(): ntok += raw.count(b"data:")
if _meas: now = _t.monotonic()
ntok += raw.count(b"data:") if now - last >= 0.5: # refresh ~2×/s, keep it cheap
now = _t.monotonic() last = now
if now - last >= 0.5: # refresh ~2×/s, keep it cheap dt = now - t0
last = now m = (engine.active or {}).get(_rid)
dt = now - t0 if m is not None:
m = (engine.active or {}).get(_rid) m["step"] = ntok
if m is not None: m["rate"] = round(ntok / dt, 1) if dt > 0 else 0.0
m["step"] = ntok yield raw
m["rate"] = round(ntok / dt, 1) if dt > 0 else 0.0
yield raw
resp_headers = self._filter_headers(rp_resp.headers, _DROP_RESP) resp_headers = self._filter_headers(rp_resp.headers, _DROP_RESP)
return StreamingResponse( return StreamingResponse(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment