borysiasty / plugin_reloader

QGIS plugin: Reloads a chosen plugin in one click (only useful for Python Plugin Developers)
GNU General Public License v3.0
19 stars 16 forks source link

Incorrect unload order for submodules #38

Closed ostr00000 closed 1 month ago

ostr00000 commented 8 months ago

I believe that this code: https://github.com/borysiasty/plugin_reloader/blob/36ddcb2a71fc117ba754ad5ccd9d86b463b28986/reloader_plugin.py#L262-L267 should be executed after call to unloadPlugin method (but before loadPlugin): https://github.com/borysiasty/plugin_reloader/blob/36ddcb2a71fc117ba754ad5ccd9d86b463b28986/reloader_plugin.py#L273-L276

This is because one could make local import in unload function to access for example a global object. If the submodule with the global object is unloaded first, then a new global object is created. Current behavior is inconsistent with manual reload (menuBar->Plugins->Manage and Install Plugins...->uncheck a plugin and then check it again) - I have no error when reloading plugin from QGIS.


Note: Why should one perform local import in initGui and unload methods in QGIS plugin instead of global import? Because submodules should only be loaded if the plugin is active. It is especially severe, when a submodule have long load time (ex. fetching data from DB) and despite plugin been disabled, it still impacts QGIS startup time.

borysiasty commented 6 months ago

Hi,

I apologize for the late reply (and the wrong order of commands). Thanks a lot for your investigation, I'll fix it within upcoming weeks!

borysiasty commented 1 month ago

Since QGIS 3.8.4, the unloading submodules is implemented in qgis.utils.unloadPlugin:

https://github.com/qgis/QGIS/pull/9851/files

so I'm just removing it from here. Will be released soon.

borysiasty commented 1 month ago

@ostr00000 Update: Finally I leave that code after unloadPlugin as you proposed, as it turns out that unloadPlugin sometimes leaves leftovers.