[GRASS-dev] Howto use a Python function as error handler in libgis

Sören Gebbert soerengebbert at googlemail.com
Fri Feb 6 14:41:30 PST 2015


Dear developers,
i am trying to register a Python function as error handler callback
using ctypes in libgis.
I use this code in the temporal framework:


{{{
def error_handler(data):
    pass

CALLBACK = CFUNCTYPE(None, c_void_p)
CALLBACK.restype = None
CALLBACK.argtypes = c_void_p

cerror_handler = CALLBACK(error_handler)

libgis.G_add_error_handler(cerror_handler, POINTER(None))
}}}

Unfortunately i get this error:

{{{
Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "/home/soeren/src/grass7.1/grass_trunk/dist.x86_64-unknown-linux-gnu/etc/python/grass/temporal/c_libraries_interface.py",
line 759, in c_library_server
    libgis.G_add_error_handler(cerror_handler, POINTER(None))
ArgumentError: argument 1: <type 'exceptions.TypeError'>: expected
CFunctionType instance instead of CFunctionType
}}}

Does anyone know what the correct way is to register a Python function
as error handler in libgis?

Any help is highly welcome.

Best regards
Soeren


More information about the grass-dev mailing list