[GRASS-dev] Howto use a Python function as error handler in libgis
Sören Gebbert
soerengebbert at googlemail.com
Wed Feb 11 04:50:54 PST 2015
Dear Developers,
any clue about how to register a Python function
as error handler in libgis using libgis.G_add_error_handler()?
Or is there any other way to recognize a fatal error call from libgis in Python?
I tried to catch the signals, unfortunately is Python not able to
catch signals emitted from a C-library.
Is it possible to write an error handler in C that can transfer a
signal that Python is able to catch using the Python API?
My current approach is a Python-thread that checks if the Python
process that accesses the C-library functions every 0.2 seconds is
still alive. The reason why i need this is, that the Python Pipe
communication object between the processes must be closed correctly to
avoid endless waiting in the receiver process/thread.
Any suggestions are welcome.
Best regards
Soeren
2015-02-06 23:41 GMT+01:00 Sören Gebbert <soerengebbert at googlemail.com>:
> 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