feat: add close() method and context manager support to Client and AsyncClient#598
Open
ServOMorph wants to merge 1 commit intoollama:mainfrom
Open
feat: add close() method and context manager support to Client and AsyncClient#598ServOMorph wants to merge 1 commit intoollama:mainfrom
ServOMorph wants to merge 1 commit intoollama:mainfrom
Conversation
…yncClient - Add close() method to Client and AsyncClient for explicit resource cleanup - Implement __enter__/__exit__ for Client to support context manager usage - Implement __aenter__/__aexit__ for AsyncClient to support async context manager usage - Allows usage: with Client() as client: ... - Allows usage: async with AsyncClient() as client: ... Closes ollama#532
|
Example API Key" |
1 similar comment
|
Example API Key" |
Author
|
@Beatrix9 Could you clarify what you mean? Are you suggesting an example for handling API keys securely? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds explicit resource management to
ClientandAsyncClientby implementing:close()method for manual cleanup__enter__/__exit__)__aenter__/__aexit__)Motivation
Closes #532
This allows users to properly clean up HTTP connections and release resources, following Python best practices.
Changes
Client (synchronous)
close()method to explicitly close the underlyinghttpx.Client__enter__and__exit__to support context manager usageAsyncClient (asynchronous)
async close()method to explicitly close the underlyinghttpx.AsyncClient__aenter__and__aexit__to support async context manager usageUsage Examples
Synchronous