Sublime Forum

What does plugin_unloaded() do?

#1

What does plugin_unloaded() do ? I have gone through the API but other than say

Plugins may also define plugin_unloaded(), to get notified just before the plugin is unloaded.

What does it mean for a plugin to be unloaded ?

0 Likes

#2

It is called when you save your Python plugin. Right after that, plugin_loaded is called.
It is also called when you put the name of your package in the ignored_packages list in your preferences. The command Package Control: Disable Package can do that for you.

Invoking plugin_unloaded and then plugin_loaded should bring your plugin into a neutral state.

For instance, you would destroy all your output panels, stop any Python threads you may be running, remove regions you might have added in views, etc.

2 Likes

#3

I tried an example code as belows:

def plugin_loaded():
	print("Plugin loaded")


def plugin_unloaded():
	print("Plugin unloaded")

I can see the response Plugin loaded in the console but not Plugin unloaded on save ?

0 Likes

#4

You should be seeing it; are you seeing any messages indicating that the plugin is being reloaded otherwise?

reloading plugin User.test
I'm loading!
reloading plugin User.test
I'm unloading!
I'm loading!
reloading plugin User.test
I'm unloading!
I'm loading!

Here the first save doesn’t trigger plugin_unloaded(), but all subsequent saves do.

Note that only python files in the root of the package are considered plugins and this will only be called for those files (and only those files will be automatically reloaded). There was an issue in previous builds (I’m not sure offhand if it has been fixed or not) wherein plugin_loaded() would get called for any Python file when it was first loaded, even if it wasn’t a plugin.

0 Likes

#5

It’s working now. Thanks for the caveat. I thought plugin_unloaded() also gets called on the first save.

0 Likes