This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Nicolas. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like you're encountering the error "aclose(): asynchronous generator is already running" when trying to close an asynchronous generator that's still in use. This often happens with streaming components like
AudioStream
or
RecognizeStream
in the LiveKit Python SDK. Here are some friendly tips to help you resolve this: • Make sure to cancel any tasks that are consuming the stream (such as
async for
loops) before you call
aclose()
. Using
asyncio.Task
can help you manage and properly cancel these tasks. • Consider wrapping your stream usage inside
async with
blocks or creating custom context managers—this can make managing the lifecycle much smoother. • Follow a clear cleanup order by canceling any dependent tasks before closing your resources, similar to how it’s handled in agent components like
AvatarRunner
. • To avoid calling
aclose()
multiple times or concurrently, add a guard that prevents re-entry. If any of this feels tricky or you'd like me to walk you through the implementation, please don’t hesitate to reach out—I’m here to help! Sources: examples/agent_dispatch.py | livekit-agents/livekit/agents/voice/agent_session.py | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...