[gdal-dev] GDAL_API_PROXY and deregistering drivers (python/win32) [SEC=UNCLASSIFIED]

Even Rouault even.rouault at mines-paris.org
Thu May 23 11:26:28 PDT 2013


Le jeudi 23 mai 2013 09:18:44, Pinner, Luke a écrit :
> Greetings,
> 
> Following on from the GDAL 1.10 JP2000 Problem/Crash thread
> (http://osgeo-org.1560.x6.nabble.com/gdal-dev-GDAL-1-10-JP2000-Problem-Cra
> sh-td5054876.html), I'm trying to use the GDAL API Proxy and deregister the
> JP2ECW driver at runtime to avoid crashes with those Pleiades JP2s.  I'm
> stuck with the ERDAS ECW/JP2 v3.3 SDK at the moment due to the licensing
> of the v.4+ SDK and the need to support ECW on Linux.  However,
> deregistering fails when opening a dataset using the API Proxy.  Below is
> a simple test script that demonstrates this.
> 
> from osgeo import gdal
> print gdal.__version__
> gdal.UseExceptions()
> 
> f='img_phr1a_p_001/img_phr1a_p_201202250025599_sen_ipu_20120504_1737-002_r1
> c1.jp2'
> 
> gdal.AllRegister()
> 
> d=gdal.GetDriverByName('JP2ECW')
> d.Deregister()
> ds=gdal.Open(f)
> print 'No PROXY:'+ds.GetDriver().GetDescription()
> del ds;ds=None
> 
> gdal.AllRegister()
> 
> d=gdal.GetDriverByName('JP2ECW')
> d.Deregister()
> ds=gdal.Open('API_PROXY:'+f)
> print 'API_PROXY:'+ds.GetDriver().GetDescription()
> del ds;ds=None
> 
> This prints:
> 1.10.0
> No PROXY:JP2OpenJPEG
> API_PROXY:JP2ECW
> 

On which OS did you run the above test ? On Linux (and provided that 
GDAL_API_PROXY_SERVER is not set to YES or gdalserver) , I get JP2OpenJPEG on 
both cases. However on Windows, I would get the same result as you.

The reason is that in the Linux case, the "server" is forked at the first use 
of it, and so it inherits the active drivers at that point. In your case, 
JP2ECW is deregistered so the forked process will not use it either.

On Windows, a new executable is launched (gdalserver) and its first step is to 
call GDALAllRegister(), which ignores any deregistering done on client side.

> I realise it's a bit of a dumb test, i.e. if gdal can open it, what's the
> problem...? But the crashes with this particular file are happening when
> running another operation after successfully opening the file. So what I
> was hoping to do was wrap a try: except: around the operation and if that
> fails, deregister the crappy (but much faster) ERDAS driver and fall back
> to the OpenJPEG driver.

Not sure to have completely followed you on this.
My understanding is that you would do :
- open the file in API_PROXY mode
- if that works (ds != None and possibly attempting to read 1 pixel since 
crashes also sometimes occur in I/O operations), use the dataset, or if you 
want to avoid client/server roundtrips, open it again in standard mode (so 
with JP2ECW)
- if that fails, deregister JP2ECW and open it as usual in standard mode (with 
JP2OpenJPEG) and re-register JP2ECW just after having opened the file, for the 
next files

I'm confident that you can do that with the current state of code.


-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list