mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Unable to close connections #218
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @eliranwong on GitHub (Feb 10, 2025).
After running ollama python library, I got resource warning ... socket not closed ... 11434 ...
I need a way to explicitly close the connection. However, the ollama client does not have a close method as openai client does.
Right now, I need to use openai library to connect to ollama server, to avoid the warning. with the openai library, I can close the connection with a close method.
I hope the ollama python library offers a way to close the connection. Appreciate your good work. Thanks.
@eliranwong commented on GitHub (Feb 10, 2025):
Remarks: I know there is a keep_alive option, but in my case I just want to close connection instead of unloading the model from memory
@ParthSareen commented on GitHub (Feb 12, 2025):
Hey! Can you point to your usage + what the OpenAI equivalent is? Thanks!
@eliranwong commented on GitHub (Feb 12, 2025):
My usage
case 1 - using ollama python package
case 1 results in warning on exit:
case 2 - using openai equivalent
In case 2, the final line
client.close()saves me from the resource warning.@ParthSareen commented on GitHub (Feb 12, 2025):
Could you try this and see if it helps - just as an experiment not recommending for actual usage:
client._client.close()@eliranwong commented on GitHub (Feb 12, 2025):
I tried your suggestion
_client.close()with Ollama python library and got error:AttributeError: 'Client' object has no attribute 'close'
@ParthSareen commented on GitHub (Feb 12, 2025):
Cool cool, thanks for testing. Will look into this and possibly expose something. Thanks for the report!
@eliranwong commented on GitHub (Feb 13, 2025):
I am looking forward to the fix. Currently, I am working on a project that supports 14 AI backends, of which only Ollama and Cohere are experiencing connection issues, while the rest are functioning properly. Since I have set Ollama as the default backend, the issue is somewhat embarrassing.
@vedbobo commented on GitHub (Feb 18, 2025):
Front end engineer closed
@BrainStone commented on GitHub (Feb 28, 2025):
You can try
client._client._client.close()@eliranwong commented on GitHub (Feb 28, 2025):
It works, many thanks.
@20246688 commented on GitHub (Mar 17, 2025):
client._client.aclose()?