Feature: Get a long-lived client object
See original GitHub issueI have an a singleton object that encapsulates S3 uploads/download as well as marshal/unmarshal for a particular type of object & destination. I would like to have it encapsulate a long-lived client object. The best I can do so far is: (given it creates self.session in __init__.)
I call shutdown in global cleanup from signal handler.
-
Is there anything wrong with using a client in this way? It seems that getting a client per request when there could be many requests could wasteful as it (may?) do a network operation on creation (or why do we wait for it?).
-
If this is kosher, could there be a better interface for it?
@property
async def client(self) -> S3Client:
"""
Get a client for S3.
TODO: is there a better way to get a long-lived client?
"""
if self._client is None:
ctx = self.session.create_client( # type: ignore
service_name="s3",
region_name=self.aws_region,
aws_access_key_id=self.aws_access_key_id,
aws_secret_access_key=self.aws_secret_access_key,
)
self._client = await ctx.__aenter__()
return self._client
async def shutdown(self) -> None:
"""
Shutdown the client.
"""
if self._client is not None:
await self._client.close()
self._client = None
Issue Analytics
- State:
- Created a year ago
- Comments:26
Top Results From Across the Web
gRPC Long-lived Streaming - Code The Cloud
Implementing gRPC long-lived streaming - a tool for cloud native applications. Use it to create watch APIs and notifications ...
Read more >ASP.NET Core - how to create a long lived RabbitMQ ...
Basically I have a basic RMQ producer POC using both the standard .NET Core RMQ client as well as EasyNetQ. All is working...
Read more >Creating Service Clients - AWS SDK for Java 1.x
Service clients in the SDK are thread-safe and, for best performance, you should treat them as long-lived objects. Each client has its own...
Read more >Subscriptions - Apollo GraphQL Docs
Unlike queries, subscriptions are long-lasting operations that can change their result over time. They can maintain an active connection to your GraphQL ...
Read more >Configurable token lifetimes - Microsoft Entra
A token lifetime policy is a type of policy object that contains token lifetime rules. This policy controls how long access, SAML, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@thehesiod lol 😃 thanks for the fixes
fix coming in https://github.com/aio-libs/aiobotocore/pull/935