fierce-zoo-69908
08/23/2025, 1:01 AMCannot register an async callback with.on()`. Use asyncio.create_task within your synchronous callback instead.`tall-airline-16756
08/23/2025, 1:01 AMtall-airline-16756
08/23/2025, 1:02 AMparticipant_disconnected event asynchronously in Python using the LiveKit SDK, you can use asyncio.create_task inside a synchronous callback. Here’s a friendly little guide to help you set it up:
1. First, define a synchronous event handler for the participant_disconnected event:
@room.on("participant_disconnected")
def on_participant_disconnected(participant):
logging.info(f"Participant disconnected: {participant.sid} {participant.identity}")
# Schedule an asynchronous task
asyncio.create_task(async_cleanup(participant))
2. Next, implement the asynchronous cleanup function:
async def async_cleanup(participant):
# Perform your async operations here
await some_async_operation(participant)
This way, your async tasks run smoothly without blocking the event loop. If you have any questions or want to chat more about this, just let me know—I’m here to help!
Sources: livekit-rtc/livekit/rtc/room.py | terminal-client/client.py