You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible call evalScript in multithread #217
I set unique named module by "createUniqueModule" function for each thread. When using these modules' evalScript funciton in multithread. I got access confit error in python.dll.
Since PythonQt is a singleton. I think there may have multithread accesing confilt somewhere in PythonQt even I have unique named module.
Let's see if I can get the necessary parts together:
You need to call PythonQt::setEnableThreadSupport(true); during the initialization of PythonQt. And then release the global Python interpreter lock (GIL) with myPythonThreadState = PyEval_SaveThread(); until just before PythonQt is finalized, when you acquire it again with PyEval_RestoreThread(myPythonThreadState).
Inbetween you should then use the PYTHONQT_GIL_SCOPE define to prefix code like createUniqueModule or evalScript. This makes sure the GIL is acquired before Python code is executed.
Note though that this means these code sections can not run in parallel (or at least only if some Python function does release the GIL, usually because of - potentially longer running - IO operations). I believe that this restriction will finally be removed in one of the next Python versions.
Activity
usiems commentedon May 23, 2024
Let's see if I can get the necessary parts together:
You need to call
PythonQt::setEnableThreadSupport(true);during the initialization of PythonQt. And then release the global Python interpreter lock (GIL) withmyPythonThreadState = PyEval_SaveThread();until just before PythonQt is finalized, when you acquire it again withPyEval_RestoreThread(myPythonThreadState).Inbetween you should then use the
PYTHONQT_GIL_SCOPEdefine to prefix code likecreateUniqueModuleorevalScript. This makes sure the GIL is acquired before Python code is executed.Note though that this means these code sections can not run in parallel (or at least only if some Python function does release the GIL, usually because of - potentially longer running - IO operations). I believe that this restriction will finally be removed in one of the next Python versions.