c++调用python时出现了以下错误:
Exception ignored in: <module 'threading' from '/usr/lib64/python3.6/threading.py'>
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 1289, in _shutdown
assert tlock.locked()
问题相关代码,请勿粘贴截图
以下是我的c++代码
void train()
{
Py_Initialize();
// 执行python脚本命令
//PyRun_SimpleString("print('hello world')\n");
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('/usr/local/python3/lib/python3.6/site-packages')");
PyRun_SimpleString("sys.path.append('/root/new_platform/cpp_DL/')"
PyObject* pModule = PyImport_ImportModule("cpython1");
if(pModule == NULL){
PyErr_Print();
cout << "module not found" << endl;
}
PyObject* pFunc = PyObject_GetAttrString(pModule, "hello");
if(!pFunc || !PyCallable_Check(pFunc)){
cout << "function not found" << endl;
}
PyEval_CallObject(pFunc, nullptr);
PyGILState_Release(state);
Py_Finalize();
}
调用的python代码cpython
import argparse
def hello():
print("parser")
parser = argparse.ArgumentParser(description='###train###')
print("parser")
运行结果及报错内容
报错:
Exception ignored in: <module 'threading' from '/usr/lib64/python3.6/threading.py'>
Traceback (most recent call last):
File "/usr/lib64/python3.6/threading.py", line 1289, in _shutdown
assert tlock.locked()
希望有人能给予我解决方法