Closed ostr00000 closed 1 month 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!
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.
@ostr00000 Update: Finally I leave that code after unloadPlugin
as you proposed, as it turns out that unloadPlugin
sometimes leaves leftovers.
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 beforeloadPlugin
): https://github.com/borysiasty/plugin_reloader/blob/36ddcb2a71fc117ba754ad5ccd9d86b463b28986/reloader_plugin.py#L273-L276This 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
andunload
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.