Skip to content
Discussion options

You must be logged in to vote

I worked it out.
It seems the main process/thread needs to let the GIL go.

int main() {
    bool Initialize{ CreateMainInterpreter() };

    try
    {
      py::module_::import("printer").attr("which")("First init");

      //py::gil_scoped_release release;  // <-- this would do the trick, but anywhere before the join should work.

      std::thread Task( []() {
        py::gil_scoped_acquire scope;
        py::subinterpreter sub = py::subinterpreter::create();
        py::subinterpreter_scoped_activate guard(sub);
        py::module_::import("printer").attr("which")("Created sub");
      } );

      py::gil_scoped_release release;
      Task.join();
    }

    catch (py::error_already_se…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ycdtosa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant