Skip to content

Commit e743b32

Browse files
committed
fix: add init err catch
1 parent 139e802 commit e743b32

1 file changed

Lines changed: 27 additions & 21 deletions

File tree

pyWrapper.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,33 @@ DataListNode *DataListCls::get(std::string key) {
136136
PyWrapper::PyWrapper() {
137137
// 仅仅为了 加载下python lib库使 其部分函数可被导出使用
138138
// https://stackoverflow.com/questions/67891197/ctypes-cpython-39-x86-64-linux-gnu-so-undefined-symbol-pyfloat-type-in-embedd
139-
dlopen(PythonSo, RTLD_GLOBAL | RTLD_NOW);
140-
141-
// if (config.count(wrapperFileKey) == 0)
142-
py::gil_scoped_acquire acquire;
143-
_wrapper = py::module::import(WrapperFile);
144-
_obj = _wrapper.attr(WrapperClass)();
145-
_wrapper_abs = _wrapper.attr("__file__").cast<std::string>(); // 获取加载的wrapper.py的绝对地址
146-
147-
_wrapperInit = _obj.attr("wrapperInit");
148-
_wrapperFini = _obj.attr("wrapperFini");
149-
_wrapperOnceExec = _obj.attr("wrapperOnceExec");
150-
_wrapperOnceExecAsync = _obj.attr("wrapperOnceExecAsync");
151-
_wrapperError = _obj.attr("wrapperError");
152-
// stream support
153-
_wrapperCreate = _obj.attr("wrapperCreate");
154-
_wrapperWrite = _obj.attr("wrapperWrite");
155-
_wrapperRead = _obj.attr("wrapperRead");
156-
_wrapperTest = _obj.attr("wrapperTestFunc");
157-
158-
py::gil_scoped_release release;
159-
StartMonitorWrapperClass(_wrapper_abs);
139+
try {
140+
dlopen(PythonSo, RTLD_GLOBAL | RTLD_NOW);
141+
142+
// if (config.count(wrapperFileKey) == 0)
143+
py::gil_scoped_acquire acquire;
144+
_wrapper = py::module::import(WrapperFile);
145+
_obj = _wrapper.attr(WrapperClass)();
146+
_wrapper_abs = _wrapper.attr("__file__").cast<std::string>(); // 获取加载的wrapper.py的绝对地址
147+
148+
_wrapperInit = _obj.attr("wrapperInit");
149+
_wrapperFini = _obj.attr("wrapperFini");
150+
_wrapperOnceExec = _obj.attr("wrapperOnceExec");
151+
_wrapperOnceExecAsync = _obj.attr("wrapperOnceExecAsync");
152+
_wrapperError = _obj.attr("wrapperError");
153+
// stream support
154+
_wrapperCreate = _obj.attr("wrapperCreate");
155+
_wrapperWrite = _obj.attr("wrapperWrite");
156+
_wrapperRead = _obj.attr("wrapperRead");
157+
_wrapperTest = _obj.attr("wrapperTestFunc");
158+
159+
py::gil_scoped_release release;
160+
StartMonitorWrapperClass(_wrapper_abs);}
161+
} catch (py::error_already_set &e) {
162+
spdlog::get("stderr_console")->error("_wrapperInit error: {}", e.what());
163+
exit(-1);
164+
return ;
165+
}
160166

161167
}
162168

0 commit comments

Comments
 (0)