Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QThread Freezes GUI
Qt 6.11 is out! See what's new in the release blog

QThread Freezes GUI

Scheduled Pinned Locked Moved Unsolved Language Bindings
pyside2qthreadpyqt5
2 Posts 2 Posters 2.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GLaDOS1105G Offline
    GLaDOS1105G Offline
    GLaDOS1105
    wrote on last edited by GLaDOS1105
    #1

    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.

    0_1535983667385_Peek 2018-09-03 22-05.gif

    However, if I use PyQt5 to run the script (replacing PySide2 module), the GUI response will not delay at all.

    0_1535984088340_Peek 2018-09-03 22-04.gif

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved