Skip to content

Commit 2b29ded

Browse files
committed
update behaivor to catch StopAsyncIteration
1 parent 7d265f3 commit 2b29ded

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

litestar/response/streaming.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,12 @@ async def _stream_with_timeout_events(self, send: Send) -> None:
151151
"""
152152
while True:
153153
start_time = time.perf_counter()
154+
chunk = self.iterator.__anext__()
155+
task = asyncio.create_task(chunk)
154156

155-
try:
156-
event = asyncio.create_task(self.iterator.__anext__())
157-
except ValueError:
158-
break
159-
160-
while not event.done():
157+
while not task.done():
161158
execution_time = time.perf_counter() - start_time
162-
await asyncio.sleep(1)
159+
await asyncio.sleep(0.01)
163160

164161
if execution_time >= self.timeout:
165162
start_time = time.perf_counter()
@@ -168,11 +165,11 @@ async def _stream_with_timeout_events(self, send: Send) -> None:
168165
"body": b"timeout ping\n",
169166
"more_body": True,
170167
}
171-
await send(stream_event)
172168

173-
start_time = time.perf_counter()
174-
175-
chunk = event.result()
169+
try:
170+
chunk = task.result()
171+
except StopAsyncIteration:
172+
break
176173

177174
stream_event: HTTPResponseBodyEvent = {
178175
"type": "http.response.body",

0 commit comments

Comments
 (0)