Comments (7)
Your implementation looks good.
from s3fs.
🫡
from s3fs.
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
from s3fs.
You mean omitting await self.session.close()
? This should ideally happen automatically for you when the instance gets cleaned up, but because that can happen in any thread and potentially at interpreter shutdown time, you may see (harmless) warnings about unclosed sockets and not run coroutines.
from s3fs.
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
from s3fs.
Correct, if you don't want to manage instances yourself, you can reuse them. fsspec caches all instances unless explicitly avoided (such as skip_instance_cache=True
), so if you use the same init arguments, you get exactly the same object back, and can expect the connection pool etc to still be there. It's up to you whether you want to use the context formalism for state hygene or not.
from s3fs.
Thank you very much again🫡
from s3fs.
Related Issues (20)
- s3fs rm fails silently HOT 1
- Error handling in _get_file HOT 2
- Add transfer configuration to support concurrent downloading HOT 1
- It is not possible to use synchronous and asynchronous calls together HOT 3
- Failed to check IAM role name HOT 2
- Access Denied when IAM policy give access (Read/Write/Listing) to only a prefix area HOT 14
- difficult to perform delete_object request instead of delete_objects using S3FileSystem HOT 7
- S3fs doesn't check again if file exists HOT 4
- Inconsistent recursive `put` behavior when running an identical command twice successively HOT 1
- open_async file is closed on arrival HOT 1
- set_session does not seem to be thread / jobs safe HOT 4
- Random XAmzContentSHA256Mismatch Errors HOT 6
- Access denied when providing an authentication token associated with a set of permission policies to S3FileSystem HOT 3
- calling flush on s3fs fails HOT 2
- s3fs 2024.3.0 fails reading glob patterns through pandas HOT 12
- Question: is awscrt useful ? HOT 2
- Errors when installing s3fs on Sagemaker Studio HOT 1
- Why isn't Pathlib supported yet? HOT 1
- Working example of using Async/Await HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from s3fs.