Fix blocking file I/O in Response.stream_file()

The async generator was using synchronous open() and read() which
blocks the event loop. Switched to anyio.open_file() for proper
async file I/O.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 18:04:10 -04:00
parent 2494034111
commit 06b7bae7c0
+4 -2
View File
@@ -464,9 +464,11 @@ class Response:
self.mimetype = guessed or "application/octet-stream"
async def file_generator():
with open(path, "rb") as f:
import anyio
async with await anyio.open_file(path, "rb") as f:
while True:
chunk = f.read(chunk_size)
chunk = await f.read(chunk_size)
if not chunk:
break
yield chunk