从 Python C API 获取回溯
我有一个 Python C API 扩展模块,偶尔会出现无信息的“MemoryError”。显然,这不是模块的异常处理程序所处理的错误。如何获得信息更丰富的错误回溯,以便找出扩展模块中出了什么问题?
也许问题应该是,鉴于我确实有扩展模块源代码,我应该怎么做才能在 MS Windows 上使用 MSVC 获得它的可调试版本?
I have a Python C API extension module which occassionally falls over with an uninformative "MemoryError". It's clearly not an error that's catered for by the module's exception handlers. How do I get a more informative error traceback so I can figure out what's gone wrong in the extension module?
Perhaps the question should be, given that I do have the extension module source code, what should I do to get a debuggable version of it with MSVC on MS Windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来扩展模块声称内存不足——当然,无论这是真是假,如果不查看扩展的源代码就无法判断。为了以防万一,内存不足可能会阻碍回溯,一个老技巧是提前获取一些内存,并在重新引发错误之前将其放入错误情况中,例如:
这不会告诉你比哪个Python更多的信息-visible 函数引发了错误(以及 Python 函数的名称等)。除此之外,您还需要编译扩展的 C 源代码以进行调试并使用一些工具(例如 gdb)。
Looks like the extension module is claiming to be out of memory -- whether that's true or false, of course, it's impossible to tell without looking at the extension's sources. Just in case it's true, so that the scarcity of memory might impede a traceback, an old trick is to get some memory earlier and drop it in the error case before reraising it, e.g:
This won't tell you much more than which Python-visible function raised the error (and what Python function called it, etc). To go beyond that you'll need to compile the extension's C sources for debugging and use some tools such as gdb.