How to run callback on timeout or tab closed?

Is there a way to run a function/callback on close?

e.g. I want to dispose database engine.

def logout(e):
        print ('user log out ')
cb2 = pn.state.on_session_destroyed(logout)
3 Likes

Nice! Wasn’t aware of on_session_destroyed

1 Like