-
Notifications
You must be signed in to change notification settings - Fork 271
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
Confused about using s3fs asynchronously #843
Comments
Your implementation looks good. |
🫡 |
Sorry to bother you, but there is another point that I don’t quite understand. What is the difference between the two? class MyS3:
def __init__(self):
self.s3 = S3FileSystem(key="AMIECjhoqrJSQZw9zl3S",
secret="SNNcoLOzxG8fX9rTjXABaiBkMlDfxAiWkQGmTH5N",
client_kwargs={'endpoint_url': "http://127.0.0.1:9000",
'region_name': "auto"})
self.session = None
async def __aenter__(self):
self.session = await self.s3.set_session(refresh=True)
return self.s3
async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.session.close()
class MyS3:
def __init__(self):
self.s3 = S3FileSystem(key="AMIECjhoqrJSQZw9zl3S",
secret="SNNcoLOzxG8fX9rTjXABaiBkMlDfxAiWkQGmTH5N",
client_kwargs={'endpoint_url': "http://127.0.0.1:9000",
'region_name': "auto"})
self.session = None
async def __aenter__(self):
self.session = await self.s3.set_session()
return self.s3
async def __aexit__(self, exc_type, exc_val, exc_tb):
pass Thank you very much for answering my question |
You mean omitting |
I noticed: Line 463 in 34a3219
In other words, I can reuse the session like the second code without calling session.close( ) and let session be garbage collected? Thank you again for your patient answer |
Correct, if you don't want to manage instances yourself, you can reuse them. fsspec caches all instances unless explicitly avoided (such as |
Thank you very much again🫡 |
After reading s3fs' documentation on asynchronous development https://s3fs.readthedocs.io/en/latest/#async, I tried a lot but only the following code seems to work
Is there any potential problem with my implementation? Thank you very much.
The text was updated successfully, but these errors were encountered: