我怎样才能“抓住”导入F2Py模块时出现seg故障? [英] How can I "catch" a seg fault while importing an F2Py module?

查看:166
本文介绍了我怎样才能“抓住”导入F2Py模块时出现seg故障?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些背景,其相关性可能会波动:

我目前拥有一些F2Py库 - 由F2Py编译的Python模块从一些Fortran代码。出于所有意图和目的,您可以将这些模块视为第三方;我目前无权访问Fortran源代码,而且我不负责编译过程。

I am currently in possesion of some F2Py libraries - Python modules compiled by F2Py from some Fortran code. For all intents and purposes, you can regard these modules as "third party"; I currently do not have access to the Fortran source code, and I am not in charge of the compilation process.

模块本身被导入到我正在帮助的程序中开发具有Python脚本支持并在多个平台上运行。

The modules themselves are imported into a program I am helping to develop that has Python scripting support and that runs on multiple platforms.

我正在努力防止因编译机器上的库版本引起的兼容性问题而导致的未来崩溃用户的计算机变得不同步。在我们的一个用户的计算机已经更改为numpy的不兼容版本时,已经出现问题,这导致在导入模块时启动时出现不可接受的seg错误。

I am trying to guard against future crashes arising from compatibility issues caused by the library versions on the compilation machine and the user's machines becoming out of sync. A problem has already occured where one of our user's machines had changed to an incompatible version of numpy, and this caused an unacceptable seg fault at startup when the module was imported.

问题:

我正在寻找一种导入F2Py模块的方法,但是这样我可以处理任何seg故障可能由于模块可能依赖的库版本不兼容而发生。我目前在调用import之前检查numpy版本,但我宁愿先导入然后再捕获任何问题:

I am looking for a way to import F2Py modules, but in such a way so that I can deal with any seg faults that may occur because of incompatible library versions that modules may depend on. I currently check for numpy version before calling import, but I would rather import first and then "catch" any problems later:

try:
    import module_name
except SegFault:
    # Deal with it.

捕获seg故障 - 特别是导入的结果 - 根本没有可能?

Is catching seg faults - specifically as a result of importing - at all possible?

推荐答案

Segfault也不例外,它是信号。您可以通过为其分配处理程序来捕获信号。

Segfault is not an exception, it's a signal. You can "catch" signals by assigning handlers to them.

import signal

def sig_handler(signum, frame):
    #deal with the signal.. 

signal.signal(signal.SIGSEGV, sig_handler)  

这篇关于我怎样才能“抓住”导入F2Py模块时出现seg故障?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆