clever-apartment-50437
10/08/2025, 9:26 PMtall-airline-16756
10/08/2025, 9:26 PMtall-airline-16756
10/08/2025, 9:27 PMawait is used on a variable or function call that ends up being None. This is quite common during shutdown, especially when cleanup routines try to await asynchronous close methods on objects that might not have been properly initialized.
A good way to fix this is by checking if an object isn’t None before you await its asynchronous close method. Here’s a simple example you can follow:
async def _safe_shutdown(self):
if self._proc_pool is not None:
await self._proc_pool.aclose()
if self._http_session is not None:
await self._http_session.close()
if self._http_server is not None:
await self._http_server.aclose()
if self._inference_executor is not None:
await self._inference_executor.aclose()
if self._prometheus_server is not None:
await self._prometheus_server.aclose()
if self._api is not None:
await self._api.aclose()
await asyncio.gather(*self._tasks, return_exceptions=True)
self._msg_chan.close()
await self._close_future
This approach helps make sure you’re never awaiting None, which should prevent that error from popping up. If you have any more questions or want me to walk you through this further, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/agent.py | rag/rag_handler.py