You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So we rely on __del__ for cleanup of resources, which is not too great. There are many posts about the danger of it, although I am not quite sure what exactly applies to a modern python version as there has been some PEPs improving the situation. Nevertheless, there seems to be a common agreement that context managers are always preferred for cleaning up resources. As AsyncAPIClient already is a context manager, we would just need to make OpenAIChatCompletionClient one as well (an async one to be more concrete).
The text was updated successfully, but these errors were encountered:
Good point. We may end up having states inside the client that requires clean up. Consider perhaps a close() method for the client class as the first step?
Right now
OpenAIChatCompletionClient
is no Context Manager and instead relies on a deletion method for cleanup. In particular it does:AsyncOpenAI
client here:autogen/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py
Line 1017 in 34bc82e
AsyncAPIClient
, which creates an AsyncHttpxClientWrapper here: https://github.com/openai/openai-python/blob/main/src/openai/_base_client.py#L1449AsyncHttpxClientWrapper
does cleanup in a deletion method here: https://github.com/openai/openai-python/blob/main/src/openai/_base_client.py#L1362So we rely on
__del__
for cleanup of resources, which is not too great. There are many posts about the danger of it, although I am not quite sure what exactly applies to a modern python version as there has been some PEPs improving the situation. Nevertheless, there seems to be a common agreement that context managers are always preferred for cleaning up resources. AsAsyncAPIClient
already is a context manager, we would just need to makeOpenAIChatCompletionClient
one as well (an async one to be more concrete).The text was updated successfully, but these errors were encountered: