Running 2 Python scripts concurrently with Boost P

2019-06-05 06:54发布

问题:

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?