`cffi` bypasses `sys.unraisablehook` for unraisable exceptions on Python 3.8
We embed Python in a native application on Windows, and this includes a number of modules built using cffi
. We've recently upgraded to Python 3.8, which introduces a hook specifically for unraisable exceptions (sys.unraisablehook
). We added support this hook, but noticed that exceptions raised in callbacks exposed via @ffi.def_extern()
were not being caught through this mechanism.
Looking at the source for _cffi_backend.c
, it looks like PyErr_WriteUnraisable
is not really used, but rather replaced with a custom implementation to add extra messaging (_my_PyErr_WriteUnraisable
). Is the right way to fix this on Python 3.8 to decorate every callback with a custom onerror
function? I'm not certain what the right solution would be otherwise, given other factors like PyPy support, the desire for limited API support (we couldn't use _PyErr_WriteUnraisableMsg
), etc.