"Critical error detected" in double import of Python module - Pybind11

80 views Asked by At

basically I have an embedded interpreter in the main thread that has to be restarted by scratch. I got crash importing a module the second time Here is the simplest code to reproduce ('datetime' just as example).

int main() {

    py::initialize_interpreter();
    py::module_::import("datetime");  //--> it works if I import modules, like 'sys', 'os'. 
    py::finalize_interpreter();

    py::initialize_interpreter();
    py::module_::import("datetime"); //--> crash here
    py::finalize_interpreter();
    return 0;
}

Running this gives: A breakpoint instruction (__debugbreak() statement or a similar call) was executed in test.exe.

I am no expert in debugging, so if I forgot to report something helpful, let me know. pybind from master branch, python 3.12, win10.

0

There are 0 answers