开发者

How to catch an exception thrown in ctypes?

开发者 https://www.devze.com 2022-12-31 00:27 出处:网络
I am working with some C code called from Python using ctypes.Somewhere in the bowels of the C library, an exception is 开发者_如何转开发occurring and/or abort() is being called.Is there any way I can

I am working with some C code called from Python using ctypes. Somewhere in the bowels of the C library, an exception is 开发者_如何转开发occurring and/or abort() is being called. Is there any way I can catch this in my Python caller code? (Platform is Linux)


You might be able to setup a signal handler on SIGABRT to handle the signal caused by abort(). However, failed assertions might go along with corrupted memory and other bad things - there's usually a reason why an assertion failed. So usually terminating the applications is the best thing you can do (except displaying/logging an error in your handler before terminating).

0

精彩评论

暂无评论...
验证码 换一张
取 消