Understanding multi threading support
Hi,
I'm just trying to implement PythonQt in our application and I try to understand the multi threading support in the library but I'm afraid I didn't understand it completely. So I have a number of questions regarding multi threading
- what is
PythonQt::setEnableThreadSupportmeant for an when should I use it. From reading the docs I would say, it is required, as soon as I use thethreadingmodule from python. Is this right? - in which situations should I use
PythonQtThreadStateSaverorPythonQtGILScope - is it save to access the properties and slots of registered objects from threads created via
threadingmodule as long as the object is not an UI object? - is it allowed to call
evalScriptfrom a Qt worker thread whenPythonQt::inithas been called in the main UI thread - is there a recommended practice what to do, If I would like to call the interpreter (
evalScript) from a worker thread.
Thank you for any help regarding these questions and btw. thank you for this great library.
Uwe
The text below just is my own experience of pythonqt and I can not make sure everything is right. If you use the C++ thread to run python codes, you need to keep a PythonQtGILScope object when python function is running because of the fucking GIL. If you just want to use the python thread,the thread can work well except some extra features. There is a example:
{
// this is a child thread.
{
PYTHONQT_ALLOW_THREADS_SCOPE;
{
PYTHONQT_GIL_SCOPE;
{call a python code which create a python thread}
//In this scope, you can call a python function and also can create a python thread.
{call another python codes or functions}
// In this time, the python thread will work.
{some C++ codes}
// In this time, the python thread will sleep.
}
{some C++ codes}
//In this scope, python thread is still working
{call a python function}
//this behavior will cause a error from python.dll
}
{some C++ codes}
//If python thread do not finish its work, it will sleep and when the code run into the PYTHONQT_ALLOW_THREADS_SCOPE again, it will be invoked.
}
被GIL整崩溃了,无法支持多线程,而且没有调试功能,pdb无法在pythonqt上独立运行,只有参照bdb源码写一份c++调试代码,但是依旧无法解决多线程GIL, 想绕过GIL使用启用多进程,结果傻眼了,直接开启了多套程序