grass.script: Load C libraries into the process in init to make grass.lib work - #7733
Open
petrasovaa wants to merge 2 commits into
Open
grass.script: Load C libraries into the process in init to make grass.lib work#7733petrasovaa wants to merge 2 commits into
petrasovaa wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Importing
grass.lib(ctypes interface to the C libraries) fails withImportError: Could not load grass_gis...in a Python process that set up a GRASS session withgj.init()orgs.setup.init(), e.g., in a Jupyter notebook. The session setup sets the dynamic library search path variable (LD_LIBRARY_PATHon Linux), but the dynamic linker reads it only at process startup, so in the already running process the GRASS libraries cannot resolve their dependencies on each other (unless the libraries' RUNPATH, i.e. the configured install prefix, happens to be valid).The library preloading approach is borrowed from the grass-session package (
load_libs()), with a few differences:libgrass_*libraries (grass-session loads every*.soin the directory) and also globs*.dylib, so it works on macOS builds where grass-session's.so-only pattern finds nothing.PATHviaos.add_dll_directory()whengrass.libis imported, which happens after init has extendedPATH, so preloading is not needed.grass.libimport fails the same way with or without preloading.mode=1(RTLD_LAZY) argument: ctypes always addsRTLD_NOWon POSIX, so the flag has no effect; the default mode matches what the generatedgrass.libloader uses.