Running 2 Python scripts concurrently with Boost Python embedded in C++

倖福魔咒の 提交于 2019-12-08 09:10:09

问题


I embedded Python in C++ using Boost Python.

I wanted to run 2 Python scripts concurrently. The scripts should also have the opportunity to access C++ member functions.

Well, when I use just 1 thread in the main interpreter it can use the member functions. But to run 2 scripts concurrently I create a new interpreter for each thread (http://docs.python.org/2/c-api/init.html#sub-interpreter-support). So scripts can be executed concurrently but they are not able to use the member functions.

This is just the general problem.


PyThreadState* Py_NewInterpreter():

Create a new sub-interpreter. This is an (almost) totally separate environment for the execution of Python code. In particular, the new interpreter has separate, independent versions of all imported modules, including the fundamental modules builtins, main and sys. The table of loaded modules (sys.modules) and the module search path (sys.path) are also separate. The new environment has no sys.argv variable. It has new standard I/O stream file objects sys.stdin, sys.stdout and sys.stderr (however these refer to the same underlying file descriptors).

So, is there no possibility to do that?

来源:https://stackoverflow.com/questions/22479669/running-2-python-scripts-concurrently-with-boost-python-embedded-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!