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