Embedded Boost :: Python and C ++: work in parallel

How can I run C ++ and Boost :: Python code in parallel without problems?

For example, in my game I want to execute Python code in parallel with C ++ code; if the Python interpreter's built-in code executes a lock cycle, such as while(True): pass , C ++ code will still work and process frames for rendering with its own loop.

I tried with boost::thread and std::thread , but if I did not join these threads with the main thread, the program would work ...

Any suggestions or examples?

+4
source share
2 answers

Your idea of ​​using a second thread for the Python interpreter should work. Make sure you use PyGILState_Ensure / Release Mechanisms wherever you want to run code that will call any Python or Boost :: Python code. You have more detailed information about this other SO file here .

+1
source

You need to use the multiprocessing module in python so that you get a separate GIL for each python thread.

0
source

Source: https://habr.com/ru/post/1496836/


All Articles