2

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Full details about GIL Tiwtiling here stackoverflow.com/questions/8009613/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.