In my add-on __init__.py
file, I have a function defined def unregister():
which unregisters all other modules. But when I exit Blender normally (Windows 10, X button), this function is never called.
Edit Note: This is normal behavior - see answer
Is there something that needs to be done before Blender executes unregister()
on exit? Or perhaps some error in my add-on may be causing this behavior? I get no warnings or errors. Only two lines print out on exit:
Saved session recovery to 'C:\Users\Moats\AppData\Local\Temp\quit.blend'
Blender quit
Maybe this is normal? Blender is saying - its over, so it doesn't matter? One other unlikely possibility is that print() doesn't function after a certain exit point. I can probably confirm this, but not easily.
If anyone knows what might be happening, or can confirm that their own unregister()
is being called on exit, I'd really appreciate it.
unregister()
function is only called when you deactivate the add-on in your preferences, as far as I'm aware. Add-ons that store settings in the preferences commonly remove them whenunregister()
is called. It would be very inconvenient if that was the case whenever Blender is closed. For an example see the add-on in this answer blender.stackexchange.com/questions/153022/… $\endgroup$ – Robert Gützkow♦ Sep 18 '19 at 13:21register()
was a sort of activation area, and 'unregister()' was the exit point of that activation. I just assumed all add-ons would be deactivated before Blender shuts down. I've noticed several add-ons doing this, so it must be a common assumption (unless they were only trying to clean up for add-on toggling). So then it would be unwise to try to initialize inregister()
and clean up inunregister()
? Such as, for example, to flush some file buffers on exit (random example). Where would be the best place to do this? $\endgroup$ – Robert Sep 18 '19 at 18:49unregister()
function doesn't get called when that happends). If anything needs to run when Blender closes you would useatexit
. $\endgroup$ – Robert Gützkow♦ Sep 18 '19 at 20:09