Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QThread Freezes GUI
GLaDOS1105 last edited by GLaDOS1105
It is not completely freezing. However, when I do some heavy tasks in QThread, the GUI responds slowly. For instance,
import sys from PySide2.QtCore import QThread from PySide2.QtWidgets import (QApplication, QWidget, PushButton,QComboBox, QVBoxLayout) class Task(QThread): def run(self): # some heavy tasks print('task started') k = 0 for i in range(10000): for j in range(50000): k += 1 print('task finished') class Gui(QWidget): def __init__(self): super().__init__() layout = QVBoxLayout() button = QPushButton('click me') button.clicked.connect(self.do_task) combobox = QComboBox() combobox.addItems(['1', '2', '3', '4', '5']) layout.addWidget(button) layout.addWidget(combobox) self.setLayout(layout) def do_task(self): self.thread = Task() self.thread.start() if __name__ == '__main__': app = QApplication(sys.argv) window = Gui() window.show() sys.exit(app.exec_())
Here is the example GIF animation.
However, if I use PyQt5 to run the script (replacing PySide2 module), the GUI response will not delay at all.
How could I make the GUI have more CPU resource or higher priority when there are other threads running at the same time?
Testing environment: Python 3.6, PySide2 5.11.1, PyQt5 5.11.2, Kubuntu 18.04 64-bit.
Looks like there's some problem with the PySide 2 implementation. You should check the bug report system to see if it's something known. If not, please consider opening a new report providing your example and as much details as possible about your current setup.