Is it possible to get a callback before Blender closes?
There are bpy.app.handlers. Unfortunately there is no handler for closing Blender.
So is there a way to to know in a script when blender is about to close?
Is it possible to get a callback before Blender closes?
There are bpy.app.handlers. Unfortunately there is no handler for closing Blender.
So is there a way to to know in a script when blender is about to close?
While we could support this via bpy.app.handlers, we decided not to add this since Python already supports exit callbacks, so you can use these (outside of Blender too - for any Python script).
See Python's atexit module.
Simple example use:
def goodbye(name, adjective):
print("Goodbye, %s, it was %s to meet you." % (name, adjective))
import atexit
atexit.register(goodbye, "Suzanne", "nice")
Note : To unregister the callback when disabling an add-on for instance, you can use :
atexit.unregister(callback)