Reputation: 21
I'm having a problem with my (game) application, which is using Boost.Python, when it comes to the scripting part. I have a client thread and a server thread that runs in the same process if you do not connect to an external server.
This is where my problems arise: It seems like the Python interpreter can't execute scripts in the client thread parallel with scripts in the server thread, as it causes the application to crash.
So my question is: Is there any possibility to run two (or more) scripts parallel in the Python interpreter? I have been searching all day and found a lot of information regarding Py_NewInterpreter, but this does not solve my problem as it uses GIL, I don't want the interpreter to lock other scripts from executing as it will cause lag on the client and/or the server side.
Upvotes: 2
Views: 652
Reputation: 5283
As of today, you cannot avoid GIL
interactions when using python threads in the same process.
You may want to have a look at multiprocessing
module which is meant to easily spawn Python processes, thus not interacting with GIL
.
Another option is to explicitly release the GIL
when its not needed in your wrapped C/C++ functions. This can be done using PyEval_SaveThread
and PyEval_RestoreThread
functions.
Upvotes: 1