Can I get the reason of shutdown inside the functi...
# ask-ai
a
Can I get the reason of shutdown inside the function which I'm assigning for "add_shutdown_callback"
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you asked! You can actually access the reason for shutdown inside the function assigned to
add_shutdown_callback
in LiveKit. The callback function can optionally take a single argument, which will be the shutdown reason—pretty handy, right? Here’s a simple example in Python to illustrate:
Copy code
async def _on_shutdown(reason: str):
    # `reason` contains the shutdown reason
    print(f"Shutting down because: {reason}")

ctx.add_shutdown_callback(_on_shutdown)
So, in this example, the
reason
parameter will hold the shutdown reason whenever the callback runs. If you need any more help with this, feel free to ask—I’m here to help! Sources: livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py