How to embed multiple python interpreters in a c++ program with pybind11?

Viewed 782

Using pybind11, I'd like to embed multiple interpreters: I want to launch multiple threads, and in each thread, start an interpreter, eval_file, and then stop the interpreter and shut down the thread.

Basically, this is a thread function:

pybind11::scoped_interpreter guard{};
pybind11::eval_file(python_filename);

Compilation is fine, but at runtime I get:

terminate called after throwing an instance of 'std::runtime_error'
  what():  The interpreter is already running

I guess this is a no-no. But why? How would it even know?

0 Answers
Related