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

Calling wait() without timeout on an unfinished QThread hangs the program

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.0
    • PySide
    • None
    • PySide/Qt 5.15.0, Python 3.8.3
    • Windows

    Description

      How to reproduce:

      Run this piece of code:

      from PySide2 import QtCore
      import time
      import sys
      
      
      class Producer(QtCore.QThread):
          def run(self):
              time.sleep(2)
              print('hi')
      
      
      if __name__ == "__main__":
          app = QtCore.QCoreApplication(sys.argv)
          producer = Producer()
          producer.start()
          print("About to call Qthread.wait()")
          producer.wait()  # hangs
          print("Qthread finished")
      

      Expected output:

      About to call Qthread.wait()
      hi
      Qthread finished
      

      This happens instead:

      About to call Qthread.wait()
      * hangs here, no error message printed *
      

      More details:

      Using an arbitrary large timeout prevents the program from hanging (this produces the expected output):

      if __name__ == "__main__":
          app = QtCore.QCoreApplication(sys.argv)
          producer = Producer()
          producer.start()
          print("About to call Qthread.wait()")
          producer.wait(1000000)  # 1000000 ms >> 2 s
          print("Qthread finished")
      

      Calling wait() on a finished QThread without timeout does not hang the program (produces the expected output):

      if __name__ == "__main__":
          app = QtCore.QCoreApplication(sys.argv)
          producer = Producer()
          producer.start()
          print("About to call Qthread.wait()")
          time.sleep(5)
          producer.wait()
          print("Qthread finished")
      

      Attachments

        Issue Links

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

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              helium Yichi Yang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes