Triggering python debugger on unraisable exception warnings

Viewed 370

I am debugging some code that uses CFFI and a c library, with python callbacks. I have some pytests around the code, with pytest set to turn warnings into errors. (That lets me know, but that is delayed notification, as the warnings are still warnings until after the test completes, as far as I can tell).

CFFI will cause unraisable exceptions when there is an error in a callback that was invoked from C. I want to debug those errors before returning to C. Is there a way to set a breakpoint on something like that, or on any unraisable exception? (These exceptions also occur when finalizing an object, and that would be a good time to set a breakpoint.) Here's an example error:

pytest.PytestUnraisableExceptionWarning: Exception ignored from cffi callback <foo.utility.method_callback.MethodCallback object at 0x10e5436a0>, trying to convert the result back to C: None
E   
E   Traceback (most recent call last):
E     File "foo/__init__.py", line 18, in foo
E       return _lib.foo(
E   TypeError: initializer for ctype 'char *' must be a cdata pointer, not bytes

I wish I could set a breakpoint in the problem callback itself, but I'm unsure which callback that is (it's not the one the error is pointing to, it's one that is nested inside there), and because of the C interface, some of my stack trace is getting lost. Because these are unraisable exceptions, normal "raise on exception" techniques don't seem to work.

I am using Intellij/pycharm as my debugger, but pdb would work too.

0 Answers
Related