Sublime Forum

Solution: on_exit event handler - is there one?

#1

As in title, i haven’t found any event handler triggered at ST’s exit.

tried on_close() - no reaction,
tried pythons ‘atexit’ package - still nothing.
upd: tried class destructor in hope it would be called at exit, with the same result
upd2: plugin_unloaded() - nothing

Is there any alternative?

Upd last: solved using on_deactivated().
If needed to catch exactly the exit moment, then use the construct like this:

#disclaimer: This code is hypotetical and was not tested as it is out of original problem.

class SomeEvents(sublime_plugin.EventListener):
    timeoutExit= Timer(None, 0)
    def exitHandler(self):
        #do stuff
        
    def on_deactivated(self,view):
        self.timeoutExit= Timer(self.exitHandler, 0)
        self.timeoutExit.start()

    def on_activated(self, _view):
        self.timeoutExit.cancel()

So “stop event” will be canceled if ST continues. The only misbehavior of this approach seems to be only when closing last open window without exiting ST itself.

0 Likes

#2

It should but it doesnt :frowning:
Even if we put aside that it’s not suitable for ST2

0 Likes