-
Notifications
You must be signed in to change notification settings - Fork 274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FastAPI async endpoint: which s3fs client should I use? Needed example #907
Comments
This is fair. It is slightly more complicated, but will allow you not to block fastAPI's event loop waiting for sync, which I htink is the main benefit you're after. Note that if you use async mode, you should create your filesystem within a coroutine, not init (unless it is itself called from within a coroutine).
I would say that async mode is more "expert" functionality. But if you are doing async programming with fastAPI already, then you qualify :)
You will block at every call to s3fs. That might be a problem in some situations, it depends on your use case. async def example_one(self):
session = await self.s3_fs.set_session()
work = await self.s3_fs._glob(...)
await session.close()
return work I think this should work fine without the explicit session calls, except you might get a warning when your process finally exits. My suggestion is, that you should have a method which sets up and caches the filesystem object
|
I created this simple DAO class in order to interface the s3 fs coroutines and its cached fs. What do you think?
|
No, I would not create and destroy a session on every call, you will find this expensive. I think the (async) method I suggested which stores the filesystem just once is better.
The code has evolved over time to make this less necessary. It's still useful for you to have control over when the session is made and closed, but the default behaviour may well be fine. |
@martindurant Do you mind proving a complete self-contained example on how you could define such a class in order to use its async coroutines in another asyn courines (i.e. FastAPI async endpoints) by means of managing the boto3 sessions/client sessions w.r.t. aiobotocore latest versions (i.e. what does the library suggest to exploit)? Thank you. I am a bit busy these days so I will come back as soon as possible... |
If I wrap the s3fs client inside a DAO class in order to create an interface to add features with the remote fs, which s3fs client should I use?
For instance, assuming I create an
async
client, because I wish to use eitherexample_one
orexample_two
"coroutines/methods" in FastAPIasync
endpoints, which example should I use?Since FastAPI handles its own loop to manage async coroutines, I believe the best approach would be to create the async client, leveraging the same FastAPI loop somehow: e.g. delegating the management to it. But:
The text was updated successfully, but these errors were encountered: