-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run gdalallregister during module initialisation #124
Conversation
…` and trial wih `gdaldumpopendatasets` at exit
Oh it is nice if indeed For the dump open datasets function, I hope we can use it to test the issues that we were seeing, so we make sure that To put the dump open datasets function in the init function, I'm wondering if it is a good idea. For proper applications you want to always close things, but I'm doubting if we should print this for interactive users that may just want to try out some things. So |
To my understanding (see links below), it does: |
Ah good, glad it also closes open datasets. So regarding this PR, I'm happy to have it. Though there are two points I still want to discuss:
|
Do we know which initializations are heavyweight and which ones are not? Maybe this should be tracked in a ticket for discussion. I'm personally okay with it, but I'm not a particularly sophisticated user of GDAL |
@mathieu17g note that making modifications to epilogue.jl, or anything under the gen folder, has no direct effect. Only if you re-run the wrapper script, or manually update the GDAL.jl file, will it make a difference. In bb6e4ad I added this. I didn't think about this in #123, so that PR didn't change any behavior. Given that, do you still think deregistering the error handlers should be done, or is that covered by gdaldestroy as well? |
OK, then since my previous test results beyond commit yeesian/ArchGDAL.jl@95f6274 in PR yeesian/ArchGDAL.jl#245, are jeopardized. I have tested ArchGDAL.jl v0.7.4 against GDAL.jl v1.2.3 with the combinations of the following additions in GDAL.jl/src/GDAL.jl : Therefore, I will restart testing from commit yeesian/ArchGDAL.jl@95f6274 (against GDAL.jl v1.2.3) when I modified the DriverManager constructor in ArchGDAL.jl/src/ArchGDAL.jl |
@visr and @yeesian here are my thoughts on the topic. Sorry it's a bit long. The current implementation of mutable struct DriverManager
function DriverManager()
drivermanager = new()
GDAL.gdalallregister()
finalizer((dm,) -> GDAL.gdaldestroydrivermanager(), drivermanager)
return drivermanager
end
end
const DRIVER_MANAGER = Ref{DriverManager}()
function __init__()
DRIVER_MANAGER[] = DriverManager()
return nothing
end 1. The error at Julia exit, exclusively comes from the call to
|
Thanks again for a thorough analysis. Some replies:
I guess it is not currently not wrapped since it is in a file called julia> using GDAL, GDAL_jll
julia> drivermanager = ccall((:GetGDALDriverManager, libgdal), Ptr{Cvoid}, ())
Ptr{Nothing} @0x000000007c92ac20
I don't fully understand, but I guess most things will be fine after julia exit. I don't know if there are concrete examples where What kind of tests did you run to determine error or no error? Running the whole ArchGDAL test suite? I prefer minimal cases, ideally GDAL.jl only, that allow us to understand the functions. I just adapted this from the using GDAL
utmsmall = joinpath(@__DIR__, "data/utmsmall.tif")
GDAL.gdalallregister()
dataset = GDAL.gdalopen(utmsmall, GDAL.GA_ReadOnly)
rm(utmsmall) # IOError because it is open (can remove it after closing julia session)
GDAL.gdaldestroy()
rm(utmsmall) # now it works I can delete the file since it is no longer open thanks to gdaldestroy This example makes sense to me. Can we craft something similar in which
@yeesian on first run |
Yes, with the sequence
|
@visr yeah I've always experienced it to be fast for myself too. If it matters, my vote's for it to run by default :) |
I wasn't able to reproduce the | | |_| | | | (_| | | Version 1.6.0 (2021-03-24)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
shell> pwd
/Users/yeesian/.julia/dev/GDAL/test
julia> using GDAL
julia> utmsmall = joinpath(@__DIR__, "data/utmsmall.tif")
"/Users/yeesian/.julia/dev/GDAL/test/data/utmsmall.tif"
julia> GDAL.gdalallregister()
julia> dataset = GDAL.gdalopen(utmsmall, GDAL.GA_ReadOnly)
Ptr{Nothing} @0x00007fb7528ce390
julia> rm(utmsmall) However, I consistently get issues with | | |_| | | | (_| | | Version 1.6.0 (2021-03-24)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> import GDAL
julia> GDAL.gdalallregister()
julia> GDAL.gdaldestroydrivermanager()
julia> GDAL.gdaldestroy()
CPLGetTLSList(): pthread_setspecific() failed! | | |_| | | | (_| | | Version 1.6.0 (2021-03-24)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> import GDAL
julia> GDAL.gdalallregister()
julia> GDAL.gdaldestroy()
CPLGetTLSList(): pthread_setspecific() failed! (Revisiting #18: although it is written in https://sgillies.net/2014/01/22/rethinking-driver-management-in-fiona-and-rasterio.html, I have not seen |
Ah that is probably just a OS filesystem difference, I think Windows locks open files. Strange that you get errors on How's this PR with the latest commit? |
gdaldestroy
registered first at exit in GDAL.jl/gen/epilogue.jl __init__()
…xit (done in `__init__()`). Plus a few modifications on GDAL utilities' tests and (#245) * For GDAL utilities tests, separate error tests from normal tests * Added GDAL import in test_images.jl * Suppressed `@time` macro in test_ospy_examples.jl * Add `@test_logs` to two tests issuing a warning in test_rasterattrtable.jl * CPLDestroyMutex Error narrowed on one test in test_gdalutilities_errors.jl * `GDAL.gdalinfo` in a try...finally block * fixed a typo in file name in "GDAL error" testset * changed `options` local variable name in `AG.gdalinfo` in case it may interfere with `options` arg * Tried to test errored `AG.galinfo` with `@test` instead of `@test_throws` * cleanup after (unsuccessful) investigation on "CPLDestroyMutex: Error = 16" issue * DriverManager modifications proposition * deregister gdaljl_errorhandler at exit * deregisterering gdaljl_errorhandler via an anonymous function to avoid test coverage decrease * Cleanup keeping gdaljl_errorhandler deregistration at exit in __init()__ * Suppressed `GDAL.cplseterrorhandler` (handled in GDAL.jl `__init__()`) and added `GDAL.gdaldestroydrivermanager` in `atexit` * Cleanup in `__init__()` with GDAL.jl PR #124 as prerequisite * Suppressed comments in ArchGDAL.jl `__init__()` function * Dropped `gdalallregister()` in `__init__()` since it has been added to GDAL.jl in PR JuliaGeo/GDAL.jl#124
@visr as discussed in yeesian/ArchGDAL.jl#245 (comment) here is a PR proposition for comments.
I have kept commented the registration at exit of
cplseterrorhandler(C_NULL)
and of a trial wihgdaldumpopendatasets
for easy revert for the former and comment for the latter