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

QInputDialog blocks the execution of child threads

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.15.4
    • 5.15.3, 6.0.0
    • PySide
    • None
    • 9a54b25b35539e0710e0dd00c95267ae7d5c8954 (pyside/pyside-setup/dev) 90732c3c862bea9659afae01b35dec0e2bdce71a (pyside/pyside-setup/6.1) 547c3cd24d3ac650d5cbd8c17c411e39499f914a (pyside/tqtc-pyside-setup/5.15)

    Description

      QInputDialog blocks the execution of child threads (implemented by Qt using QRunnable + QThreadPool, QThread, QThread + QObject or using python's threading module).

      In the following demo the threads are started but as soon as the QInputDialog is shown, the execution of the threads is blocked, when the QInputDialog is closed the threads resume their execution.

       

      import sys
      import threading
      import time
      
      from PySide6 import QtCore, QtWidgets
      
      
      class Runnable(QtCore.QRunnable):
          def run(self):
              fun()
      
      
      class Thread(QtCore.QThread):
          def run(self):
              fun()
      
      
      class Worker(QtCore.QObject):
          @QtCore.Slot()
          def task(self):
              fun()
      
      
      def fun():
          for i in range(10):
              print(i)
              time.sleep(1)
      
      
      def handle_timeout():
          value, ok = QtWidgets.QInputDialog.getInt(
              None, "QInputDialog::getInt()", "Percentage:", 25, 0, 100, 1
          )
      
      
      def main():
          app = QtWidgets.QApplication(sys.argv)
      
          w = QtWidgets.QWidget()
          w.resize(640, 480)
          w.show()
      
          runnable = Runnable()
          QtCore.QThreadPool.globalInstance().start(runnable)
      
          threading.Thread(target=fun, daemon=True).start()
      
          test_thread = Thread(app)
          test_thread.start()
      
          worker = Worker()
          worker_thread = QtCore.QThread(app)
          worker.moveToThread(worker_thread)
          worker_thread.started.connect(worker.task)
          worker_thread.start()
      
          QtCore.QTimer.singleShot(3 * 1000, handle_timeout)
      
          ret = app.exec()
          test_thread.quit()
          test_thread.wait()
          worker_thread.quit()
          worker_thread.quit()
          sys.exit(-1)
      
      
      if __name__ == "__main__":
          main()
      

      The problem happens in PySide2 and PySide6, it does not happen in PyQt5 or PyQt6.

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            eyllanesc Edwin Christian Yllanes Cucho
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes