Reputation: 883
I planning to write a python script that utilizes some multi-threaded c++ code I'm working on. The c++ code will not modify any values in the python runtime. Will python's global interpreter lock prevent the threads in the c++ code from executing in parallel? If so, what are some good resources to understand how to get around this?
The python script will only call an interface exposed by the c++ code: void notify_btn_pressed(int btn_id)
. Python and the c++ code will have no other interaction.
Upvotes: 1
Views: 352
Reputation: 28870
The GIL is a Python Interpreter lock. The Python bytecode interpreter doesn't know what your C++ library is doing behind the scenes. It doesn't have any way to prevent your C++ code from creating additional threads and doesn't attempt to prevent you from doing that.
Here is some background on the GIL and native code that explains this. And here is more general information about the GIL. These references are for Python 3.x, but Python 2.x works the same way. You can change the 3
to 2
in the URLs to see the corresponding (and nearly identical) Python 2.x docs.
Upvotes: 3