white-scientist-26058
12/04/2025, 12:02 PMapi.LiveKitAPI object in a large application in Python. would placing it in a container class with static accessors and mutex locks suffice? how can i ensure it gets properly closed when the process exits? i'm troubleshooting some memory leaks and this is a potential suspectrefined-appointment-81829
12/04/2025, 7:44 PMwhite-scientist-26058
12/05/2025, 12:26 PMLiveKitAPI object open at any given point, but from this example it seems to not be relevant, so long as they're properly cleaned up?refined-appointment-81829
12/05/2025, 12:29 PMjolly-air-155
12/05/2025, 12:32 PMwhite-scientist-26058
12/05/2025, 12:46 PMjolly-air-155
12/05/2025, 12:50 PMasync with LiveKitAPI() as api or cache it for later use should be fine, like in job ctx it’s defined as
@functools.cached_property
def api(self) -> api.LiveKitAPI:
"""Returns an LiveKitAPI for making API calls to LiveKit.
Credentials are sourced from environment variables if not provided explicitly.
When starting via the worker, values passed in `WorkerOptions` are exported to
LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET so this API is always
usable inside job entrypoints.
"""
return api.LiveKitAPI(session=http_context.http_session())
if you use your own aiohttp.ClientSession instance as session and will close it properly, api.aclose() is not neededwhite-scientist-26058
12/05/2025, 12:51 PMjolly-air-155
12/05/2025, 12:52 PMwhite-scientist-26058
12/05/2025, 12:52 PMwhite-scientist-26058
12/05/2025, 12:52 PM