Py学习  »  Python

如何用pybind11在c++程序中嵌入多个python解释器?

Colin • 5 年前 • 871 次点击  

使用pybind11,我想嵌入多个解释器:我想启动多个线程,在每个线程中,启动一个解释器,eval_文件,然后停止解释器并关闭线程。

基本上,这是一个线程函数:

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

编译是可以的,但是在运行时我得到:

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

我想这是不可以的。但是为什么?它怎么会知道呢?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50237
 
871 次点击