Mailing List Archive

How best to handle SystemError in ctypes callback
With the following code:

import ctypes
> import readline
> from ctypes.util import find_library
>
> rl = ctypes.cdll.LoadLibrary(find_library('readline'))
>
> rl_redisplay = rl.rl_redisplay
> rl_redisplay.restype = None
> rl_redisplay.argtypes = None
>
> rl_redisplay_function = ctypes.c_void_p.in_dll(rl, 'rl_redisplay_function')
>
> def _wrapper():
> rl_redisplay()
>
> fp = ctypes.CFUNCTYPE(None)(_wrapper)
> rl_redisplay_function.value = ctypes.cast(fp, ctypes.c_void_p).value
>
> input('enter ctrl-c now')
>

What is the best or correct way to handle SystemError when a Ctrl-c happens
at the input prompt? Is a try/except around rl_redisplay the best or
correct approach?

Based on the docs for SystemError (
https://docs.python.org/3/library/exceptions.html#SystemError), I don't
want to mask/hide an internal error.

Jarrod
--
https://mail.python.org/mailman/listinfo/python-list