Open
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
We have noticed strange exceptions being logged in the asyncio runtime about "close()" being called on an already closed client. It took us a while to understand what was going on, but it seems to all make sense now: We are creating a Python thread to do some processing which involves creating OpenAI client instances to make completion requests. When the destructor creates a task, the thread context will be the garbage collector, which is the main thread, not the thread which created the client.
To Reproduce
- Create a thread in python
- Use for example
asyncio.run()
to call anasync
function which eventually uses an OpenAI client to make a completion request. - Observe strange exceptions about clients being closed that are already closed.
Code snippets
OS
any
Python version
Python 3.12
Library version
openai v1.93.0