You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently using fastapi to return a streaming response from results in google cloud storage. So, with fastapi, I have a few things that I use that make me want to use the async def options (asyncpg, aiohttp). But, if I do that my understanding is that as soon as I do blocking io in that same thread I'm going to get a stalled event loop.
As an option, I'm wondering if I can use this library and tack smart_open inside and expect it to continue working and not stall my event loop? Or perhaps there's a better/alternative way to patch smart open into this library in place of the regular open call?
Here's what I'm executing:
from smart_open import open
import aiofiles
aiofiles.threadpool.sync_open = open
async def download(request: Request) -> StreamingResponse:
async def generate_response():
async with aiofiles.open(f"gs://{bucket_name}/{file_name", 'rb') as f:
while chunk := await f.read(2**16):
yield chunk
return StreamingResponse(generate_response())
The text was updated successfully, but these errors were encountered:
I wouldn't override aiofiles.threadpool.sync_open with smart_open, other modules in your codebase maybe depend on aiofiles (or will in the future) and that might mess them up. It's a very global change.
What aiofiles does is just run functions in a thread pool. Maybe you can run the smart_open stuff in a threadpool yourself?
I am currently using fastapi to return a streaming response from results in google cloud storage. So, with fastapi, I have a few things that I use that make me want to use the
async def
options (asyncpg, aiohttp). But, if I do that my understanding is that as soon as I do blocking io in that same thread I'm going to get a stalled event loop.As an option, I'm wondering if I can use this library and tack smart_open inside and expect it to continue working and not stall my event loop? Or perhaps there's a better/alternative way to patch smart open into this library in place of the regular open call?
Here's what I'm executing:
The text was updated successfully, but these errors were encountered: