Discussion:
[Community] WorldMill logging OGR Warnings to stdout
Michael Weisman
2011-07-29 18:19:48 UTC
Permalink
Hi all,

First of all, I realize that WorldMill hasn't been touched since 2007 or something and this issue may never be fixed.

I am writing a command line utility that scans a directory of files with WorldMill to generate metadata from the schemas and geometries. If a workspace is created with a file that cannot be read by OGR, I get warnings about null pointers in OGR_DS_GetLayerCount and OGR_DS_Destroy (ERROR 10: Pointer 'hDS' is NULL in 'OGR_DS_GetLayerCount' and ERROR 10: Pointer 'hDS' is NULL in 'OGR_DS_Destroy') sent to stdout, and therefore onto the user's console. Is there any way to silence these warnings as they are mostly harmless for my uses, but somewhat scary for end users?

You can reproduce this with the sample below:

from mill import workspace
w = workspace("/") # This of course assumes you don't have a shapefile or something in /
w.collections

Thanks,

Michael

--
Michael Weisman
@mweisman

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20110729/42b4a845/attachment.htm>
Sean Gillies
2011-07-29 19:31:46 UTC
Permalink
Post by Michael Weisman
Hi all,
First of all, I realize that WorldMill hasn't been touched since 2007 or
something and this issue may never be fixed.
I am writing a command line utility that scans a directory of files with
WorldMill to generate metadata from the schemas and geometries. If a
workspace is created with a file that cannot be read by OGR, I get warnings
Pointer 'hDS' is NULL in 'OGR_DS_GetLayerCount' and?ERROR 10: Pointer 'hDS'
is NULL in 'OGR_DS_Destroy')?sent to stdout, and therefore onto the user's
console. Is there any way to silence these warnings as they are mostly
harmless for my uses,?but somewhat scary for end users?
from mill import workspace
w = workspace("/") # This of course assumes you don't have a shapefile or something in /
w.collections
Thanks,
Michael
Hi Michael,

Short of modifying the OGR code, you probably have to tamper with
stdout during execution. Alex Martelli has some good advice at

http://stackoverflow.com/questions/2828953/silent-the-stdout-of-a-function-in-python-without-trashing-sys-stdout-and-restori
--
Sean Gillies
Programmer
Institute for the Study of the Ancient World
New York University
Howard Butler
2011-07-29 20:25:31 UTC
Permalink
Post by Michael Weisman
Hi all,
First of all, I realize that WorldMill hasn't been touched since 2007 or
something and this issue may never be fixed.
I am writing a command line utility that scans a directory of files with
WorldMill to generate metadata from the schemas and geometries. If a
workspace is created with a file that cannot be read by OGR, I get warnings
Pointer 'hDS' is NULL in 'OGR_DS_GetLayerCount' and ERROR 10: Pointer 'hDS'
is NULL in 'OGR_DS_Destroy') sent to stdout, and therefore onto the user's
console. Is there any way to silence these warnings as they are mostly
harmless for my uses, but somewhat scary for end users?
With a relatively recent (>1.6) OGR:

ogr.UseExceptions()

worldmill's __del__ methods should be adjusted to check if their references are null before calling *Destroy methods on them too.
Sean Gillies
2011-07-29 20:34:00 UTC
Permalink
Post by Howard Butler
Post by Michael Weisman
Hi all,
First of all, I realize that WorldMill hasn't been touched since 2007 or
something and this issue may never be fixed.
I am writing a command line utility that scans a directory of files with
WorldMill to generate metadata from the schemas and geometries. If a
workspace is created with a file that cannot be read by OGR, I get warnings
Pointer 'hDS' is NULL in 'OGR_DS_GetLayerCount' and ERROR 10: Pointer 'hDS'
is NULL in 'OGR_DS_Destroy') sent to stdout, and therefore onto the user's
console. Is there any way to silence these warnings as they are mostly
harmless for my uses, but somewhat scary for end users?
ogr.UseExceptions()
Ah, right, but since Worldmill uses the C API and not ogr.py, it means
a call (using ctypes) to CPLSetErrorHandler.
--
Sean
Michael Weisman
2011-07-29 23:02:30 UTC
Permalink
Thanks for the tips Sean.

Simply suppressing stdout (as well as stderr) didn't work. My guess is the OGR messages are coming in below where the python session can see them.

Setting the error handler to CPLQuietErrorHandler with a call to CPLSetErrorHandler after creating a session did exactly what I needed.

Thanks,

Michael
Post by Sean Gillies
Post by Howard Butler
Post by Michael Weisman
Hi all,
First of all, I realize that WorldMill hasn't been touched since 2007 or
something and this issue may never be fixed.
I am writing a command line utility that scans a directory of files with
WorldMill to generate metadata from the schemas and geometries. If a
workspace is created with a file that cannot be read by OGR, I get warnings
Pointer 'hDS' is NULL in 'OGR_DS_GetLayerCount' and ERROR 10: Pointer 'hDS'
is NULL in 'OGR_DS_Destroy') sent to stdout, and therefore onto the user's
console. Is there any way to silence these warnings as they are mostly
harmless for my uses, but somewhat scary for end users?
ogr.UseExceptions()
Ah, right, but since Worldmill uses the C API and not ogr.py, it means
a call (using ctypes) to CPLSetErrorHandler.
--
Sean
_______________________________________________
Community mailing list
Community at lists.gispython.org (mailto:Community at lists.gispython.org)
http://lists.gispython.org/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20110729/ec93d115/attachment.htm>
Loading...