Skip to content

Add a method to unload geodiff library from python #205

Open
@wonder-sk

Description

@wonder-sk

It would be useful to have a shutdown() function in pygeodiff that would force unload of the loaded dynamic library using ctypes. This would help especially on Windows, where the .pyd file gets write-protected when it gets loaded, and then QGIS plugin manager is unable to upgrade/reinstall Mergin Maps plugin, because it is not possible to delete the .pyd file. Having the shutdown() function would allow us to use it in plugin's unload() handler to remove the write protection lock.

This works fine on Windows to release the lock:

from _ctypes import FreeLibrary
geodiff = pygeodiff.GeoDiff()
FreeLibrary(geodiff.clib.lib._handle)

As a part of this, it would be good to do a bit of code refactor: GeoDiffLib class now handles both library loading and handling of context. We should separate those, because the library can be loaded just once, but there may be multiple contexts (with different logging setups). The library (ctypes.CDLL instance) could be stored at the module level and lazy-loaded.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions