在以下代码的第二次调用中,我的应用程序SEGFULT,因此我想我遗漏了一些东西:
Py_Initialize();
pName = PyString_FromString("comp_macbeth");
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if(pModule == NULL) {
PyErr_Print();
Py_Finalize();
return;
}
pFunc = PyObject_GetAttrString(pModule, "compute");
/* pFunc is a new reference */
if (!pFunc || !PyCallable_Check(pFunc) ) {
PyErr_Print();
Py_Finalize();
return;
}
Py_Finalize();
comp_macbeth.py正在导入numpy。如果我删除numpy导入,一切都很好。这是一个numpy bug,还是我遗漏了一些关于导入的内容
从Py_Finalize docs开始:
显然,努比就是其中之一。另见Numpy讨论中的this message
只调用
Py_Initialize()
一次,然后清理at exit,这是一种方法。(而且速度也应该更快!)在我的模块初始化部分有这个,但是URL不再存在了。如果有帮助:
相关问题 更多 >
编程相关推荐