From f69a06e7fcb938df84e4b0602e4a1eb7b07b647d Mon Sep 17 00:00:00 2001 From: Martin Boos Date: Sat, 26 Oct 2019 10:02:46 +0200 Subject: [PATCH] * Fix #263: unload native lib before updating --- metadata.txt | 4 +++- plugin/util/mp_helper.py | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/metadata.txt b/metadata.txt index 2bfaedd..f1ae5dc 100644 --- a/metadata.txt +++ b/metadata.txt @@ -13,7 +13,7 @@ about=Plugin which reads vector tiles according to Mapbox' Vector Tiles specific * Nextzen.org * OpenInfraMap.org This Python plugin uses prebuilt C++ binaries for performance reasons. -version=3.2.1 +version=3.2.2 author=Martin Boos email=geometalab@gmail.com @@ -23,6 +23,8 @@ email=geometalab@gmail.com # Uncomment the following line and add your changelog: changelog= + ---3.2.2--- + * Fix: Make sure native library is unloaded before trying to update it ---3.2.1--- * Fix: Loading error on Mac * Fix: Loading of native decoding library diff --git a/plugin/util/mp_helper.py b/plugin/util/mp_helper.py index b041de2..0a11525 100644 --- a/plugin/util/mp_helper.py +++ b/plugin/util/mp_helper.py @@ -53,6 +53,8 @@ def _get_lib_path(): if not os.path.isdir(temp_dir): os.makedirs(temp_dir) if os.path.isfile(temp_lib_path) and os.path.getmtime(temp_lib_path) != os.path.getmtime(lib_path): + info("Updating native lib...") + unload_lib() os.remove(temp_lib_path) if not os.path.isfile(temp_lib_path): shutil.copy2(lib_path, temp_dir) @@ -62,11 +64,13 @@ def _get_lib_path(): def load_lib(): global _native_lib_handle + + path = _get_lib_path() + if _native_lib_handle: - info("The native dll is already loaded, not loading again...") + info("The native lib is already loaded, not loading again...") else: - info("Loading native dll...") - path = _get_lib_path() + info("Loading native lib...") if path and os.path.isfile(path): try: lib = cdll.LoadLibrary(path) @@ -97,7 +101,7 @@ def unload_lib(): global _native_lib_handle system = platform.system() try: - info("Unloading native dll...") + info("Unloading native lib...") if _native_lib_handle: if system == "Windows": from ctypes import windll @@ -106,9 +110,9 @@ def unload_lib(): else: _native_lib_handle.dlclose() else: - info("Dll already unloaded") + info("Native lib already unloaded") except Exception: - critical("Unloading native dll failed on {}: {}", system, sys.exc_info()) + critical("Unloading native lib failed on {}: {}", system, sys.exc_info()) finally: _native_lib_handle = None