pybind11-来自不同线程的调用函数
我在亲爱的imgui中具有控制台
python错误通常显示在控制台中
static std::string in;
if (ImGuiCP::InputText("##InputCommand", &in)) {
py::initialize_interpreter();
try {
py::exec(in);
} catch (pybind11::error_already_set &e) {
cout << e.what();
}
py::finalize_interpreter();
}
,
这种
py::initialize_interpreter();
代码在没有
static std::string in;
if (ImGuiCP::InputText("##InputCommand", &in)) {
try {
py::exec(in);
} catch (pybind11::error_already_set &e) {
cout << e.what();
}
}
错误的情况下工作, 正常执行,如果错误在Python中,则处理捕获量,即,它在控制台中显示错误,此后该应用程序紧密冻结
I have console in Dear ImGui
such code works without errors, python errors are normally displayed in the console
static std::string in;
if (ImGuiCP::InputText("##InputCommand", &in)) {
py::initialize_interpreter();
try {
py::exec(in);
} catch (pybind11::error_already_set &e) {
cout << e.what();
}
py::finalize_interpreter();
}
but I don't need to create a new interpreter every time, I want to create it once
in main I write
py::initialize_interpreter();
in imgui code
static std::string in;
if (ImGuiCP::InputText("##InputCommand", &in)) {
try {
py::exec(in);
} catch (pybind11::error_already_set &e) {
cout << e.what();
}
}
valid code is executed normally, and if the error is in python, it handles the catch, that is, it displays the error in the console, and after that the application freezes tightly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论