Better use of pybind11 scoped interpreter
The following discussion from !4569 should be addressed:
-
@chleh started a discussion: (+1 comment) @bilke, I can see the next problem at the horizon. From the pybind11 docs:
/** \rst Scope guard version of `initialize_interpreter` and `finalize_interpreter`. This a move-only guard and only a single instance can exist. See `initialize_interpreter` for a discussion of its constructor arguments. .. code-block:: cpp #include <pybind11/embed.h> int main() { py::scoped_interpreter guard{}; py::print(Hello, World!); } // <-- interpreter shutdown \endrst */ class scoped_interpreter
We should remove the
std::optional<pybind11::scoped_interpreter> _py_scoped_interpreter;
member, soon. Yes, I suggested adding it, but maybe it was not a very robust hint. I assume as soon as people start playing around with OGS bindings in their Python scripts, they will face strange errors.I guess we need some ref-counted thread-safe global variable taking care of the embedded Python interpreter (shared_ptr and mutex).