-
Notifications
You must be signed in to change notification settings - Fork 150
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
File descriptor leak #84
Comments
i think this would be pretty good since the anthropic client wraps a httpx client and usually we want to use it like a context manager too
|
Thanks for filing! You're correct that the library is intended to be instantiated once, not on every request, but I expect we'll add |
Out of curiosity, can you share why you needed/wanted to instantiate the client in a loop like this? |
Sorry for the delay here, this is out in https://github.com/anthropics/anthropic-sdk-python/releases/tag/v0.3.7 and will be published to pypi soon. |
I have tested anthropic 0.3.11 and 0.2.9 , both might have memory leak . code 1 : def send_something(): if name == "main": code 2 : `@retry(stop=stop_after_attempt(5), wait=wait_exponential(max=10), retry=retry_if_exception_type((ConnectionResetError,anthropic.InternalServerError) )) def send_something(): if name == "main": Both code led to File descriptor leak eventually after 10000-20000 loops . I ever tried to remove the retry and the same File descriptor leak happened . When changed to use
everything is fine . no File descriptor leak at all . |
I'm guessing this is just not recommended to init the Client on each api call like this but if you are to do something like the below you get an ever growing number of open files as indicated by
lsof
until I hit anOSError
.I can fix this by calling
client._client.close()
but seems like it would be nicer to expose aclose()
method or enable use of the client as a context manager. Suggestion here: #83Or if this is just totally the wrong way to use the client maybe this could be mentioned in the Readme.
Thanks!
The text was updated successfully, but these errors were encountered: