If i were to have exception in entrypoint, but als...
# ask-ai
f
If i were to have exception in entrypoint, but also configured add_shutdown_callback functions, would it run the callbacks after the exception is caught?
t
Thanks for reaching out, Mok. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
add_shutdown_callback
function is meant to run during a controlled shutdown process, usually after the entrypoint function finishes. However, it’s important to note that it’s not clearly guaranteed these callbacks will run if the entrypoint encounters an unhandled exception. To help make sure your cleanup tasks always get executed—even when exceptions happen—you might want to wrap your entrypoint logic in a
try/finally
block. Then, you can place the necessary cleanup code inside the
finally
section. This approach gives you a bit more peace of mind that everything will be handled properly. Sources: examples/voice_agents/basic_agent.py | Inside a session | LiveKit Docs | Job lifecycle | LiveKit Docs | Session recording and transcripts | LiveKit Docs | main.py
The
add_shutdown_callback
function is meant to run during a controlled shutdown process, usually after the entrypoint function finishes. That said, it's not completely clear if these callbacks will still run if the entrypoint encounters an unhandled exception. To make sure your cleanup tasks are reliably executed—even when exceptions happen—a good approach is to wrap your entrypoint logic in a
try/finally
block and place the necessary cleanup code inside the
finally
section. This way, you can feel confident that your cleanup will always be taken care of.