mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 23:00:17 +00:00
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:
+4
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user