I'd like to extend PythonQt to support Python threads. This mainly consists of adding guard code (macros) to swap in the thread state before calls into the Python library.
Has anyone had experience with this issue?
If I make the changes, would there be interest in integrating them into the repository?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I considered the effort and one part are the GIL macros that you will need.
The other part is that you have to ensure thread-safety in the global PythonQt structures (the class info hashes etc.). I suggest to make it an optional feature (so that it can be compiled with and without thread support, e.g. using a #ifdef PYTHONQT_WITH_THREADSUPPORT macro).
You need to find all places where the code enters Python and also all places where Qt is entered (to release the GIL while being in Qt).
I am willing to integrate you changes if they can be turned off at compile time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Great. I've started the work and it looks like there can be a simple macro that gets inserted into the beginning of each function that calls into Python. When threads are enabled it will define an auto class that handles the GIL. Something like this:
I’m trying to run multiple python threads simultaneously but am encountering thread blocking that I don’t know the best way of solving. The threads run fine through Python alone but not when run from a Qt UI with PythonQt. The last post for this topic was in 2012. Has support for Python threads been added since then or is there a workaround?
Other related topics within this forum that I found are: PythonQt and Garbage Collection (Last Post 2011) Threadsafe PythonQt (Last Post 2010)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'd like to extend PythonQt to support Python threads. This mainly consists of adding guard code (macros) to swap in the thread state before calls into the Python library.
Has anyone had experience with this issue?
If I make the changes, would there be interest in integrating them into the repository?
I considered the effort and one part are the GIL macros that you will need.
The other part is that you have to ensure thread-safety in the global PythonQt structures (the class info hashes etc.). I suggest to make it an optional feature (so that it can be compiled with and without thread support, e.g. using a #ifdef PYTHONQT_WITH_THREADSUPPORT macro).
You need to find all places where the code enters Python and also all places where Qt is entered (to release the GIL while being in Qt).
I am willing to integrate you changes if they can be turned off at compile time.
Great. I've started the work and it looks like there can be a simple macro that gets inserted into the beginning of each function that calls into Python. When threads are enabled it will define an auto class that handles the GIL. Something like this:
I'll look into the Qt side of things next.
I’m trying to run multiple python threads simultaneously but am encountering thread blocking that I don’t know the best way of solving. The threads run fine through Python alone but not when run from a Qt UI with PythonQt. The last post for this topic was in 2012. Has support for Python threads been added since then or is there a workaround?
Other related topics within this forum that I found are:
PythonQt and Garbage Collection (Last Post 2011)
Threadsafe PythonQt (Last Post 2010)
As far as I know, this is not yet supported.
It would require to
a) make PythonQt thread-safe
b) release/lock the GIL whenever entering Qt/Python