Subscribe to App Shutdown Event

If you want to execute code before the Kit application closes, you can subscribe to the app shutdown event. This will allow you to provide a callback function that is executed when the shutdown event occurs. This is useful for any sort of cleanup code that you want to perform before the app closes.

import carb.events
import omni.kit.app

# Stream where app sends shutdown events
shutdown_stream = omni.kit.app.get_app().get_shutdown_event_stream()

def on_event(e: carb.events.IEvent):
    if e.type == omni.kit.app.POST_QUIT_EVENT_TYPE:
        print("We are about to shutdown")

sub = shutdown_stream.create_subscription_to_pop(on_event, name="name of the subscriber for debugging", order=0)