Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-803

QThread Freezes GUI

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1: Critical
    • Resolution: Fixed
    • Affects Version/s: 5.11.1
    • Fix Version/s: 5.14.2
    • Component/s: PySide
    • Labels:
      None
    • Environment:
      Python 3.6, PySide2 5.11.1, PyQt5 5.11.2. This problem would occur in both Linux (Kubuntu 18.04.1) and Windows 10 (so far as I have tested).
    • Platform/s:
      All

      Description

      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, QPushButton, 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.

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              ctismer Christian Tismer
              Reporter:
              alan13wake Sean Wu
              Votes:
              10 Vote for this issue
              Watchers:
              16 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: