Skip to content

Commit

Permalink
Merge pull request #9863 from qgis/backport-9851-to-release-3_6
Browse files Browse the repository at this point in the history
[Backport release-3_6] Remove plugin module path  when unloading
  • Loading branch information
m-kuhn committed Apr 26, 2019
2 parents 11edd8f + 9bfb95a commit 1c86308
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions python/utils.py
Expand Up @@ -28,7 +28,7 @@
"""

from qgis.PyQt.QtCore import QCoreApplication, QLocale, QThread
from qgis.PyQt.QtCore import QCoreApplication, QLocale, QThread, qDebug
from qgis.PyQt.QtWidgets import QPushButton, QApplication
from qgis.core import Qgis, QgsMessageLog, qgsfunction, QgsMessageOutput
from qgis.gui import QgsMessageBar
Expand Down Expand Up @@ -411,12 +411,23 @@ def _unloadPluginModules(packageName):
if hasattr(sys.modules[mod], 'qCleanupResources'):
sys.modules[mod].qCleanupResources()
except:
pass
# Print stack trace for debug
qDebug("qCleanupResources error:\n%s" % traceback.format_exc())

# try removing path
if hasattr(sys.modules[mod], '__path__'):
for path in sys.modules[mod].__path__:
try:
sys.path.remove(path)
except ValueError:
# Discard if path is not there
pass

# try to remove the module from python
try:
del sys.modules[mod]
except:
pass
qDebug("Error when removing module:\n%s" % traceback.format_exc())
# remove the plugin entry
del _plugin_modules[packageName]

Expand Down

0 comments on commit 1c86308

Please sign in to comment.