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

QThread.wait() stalls indefinitely

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.15.0
    • PySide
    • None
    • Win10 Pro
      Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
    • Windows

    Description

      I seem to have come across an issue with QThread.wait() after an upgrade from 5.14.x to 5.15.0. QThread.wait() stalls indefinitely now, and my assumption is that it could be related to QThread refactorings i've seen in the release announcement. Maybe it's also related to the new default deadline parameter, which is a QDeadlineTimer(QDeadlineTimer.Forever) instance. When QThread.wait(int) is invoked, there seems to be no problem.

       

      Here is a minimal reproduction:

      from logging import getLogger
      
      from PySide2.QtCore import QThread
      
      
      logger = getLogger(__name__)
      
      
      class WorkerThread(QThread):
      
          def run(self):
              self.sleep(1)
      
      
      def test_qthread_wait_stalls_indefinitely_without_arguments():
      
          thread = WorkerThread()
      
          assert not thread.isRunning()
          assert not thread.isFinished()
      
          logger.info(f"start()")
          thread.start()  # async
      
          assert thread.isRunning()
          assert not thread.isFinished()
      
          logger.info(f"Before wait()")
          thread.wait()  # default deadline argument makes wait stall
          logger.info(f"After wait()")  # never reached
      
      
      def test_qthread_wait_succeeds_with_integer_argument():
      
          thread = WorkerThread()
      
          assert not thread.isRunning()
          assert not thread.isFinished()
      
          logger.info(f"start()")
          thread.start()  # async
      
          assert thread.isRunning()
          assert not thread.isFinished()
      
          logger.info(f"Before wait()")
          thread.wait(3)  # using int here makes wait() not stall
          logger.info(f"After wait()")
          # waiting for proper thread destruction omitted
      

      Failing (QDeadlineTimer/default):

      ============================= test session starts =============================
      platform win32 -- Python 3.8.3, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- d:\path\to\.tox\unittests_ui\scripts\python.exe
      cachedir: .tox\unittests_ui\.pytest_cache
      PySide2 5.15.0 -- Qt runtime 5.15.0 -- Qt compiled 5.15.0
      rootdir: D:\my\project, configfile: tox.ini
      plugins: cov-2.10.1, mock-3.3.1, qt-3.3.0
      collecting ... collected 2 items
      
      tests/unittests/ui/test_minimal_reproduction.py::test_qthread_wait_stalls_indefinitely_without_arguments
      -------------------------------- live log call --------------------------------
      INFO     test_minimal_reproduction:test_minimal_reproduction.py:35 start()
      INFO     test_minimal_reproduction:test_minimal_reproduction.py:41 Before wait()
      # ...to infinity and beyond

      Passing (int):

      tests/unittests/ui/test_minimal_reproduction.py::test_qthread_wait_succeeds_with_integer_argument
      ------------------------------- live log call --------------------------------
      INFO     test_minimal_reproduction:test_minimal_reproduction.py:56 start()
      INFO     test_minimal_reproduction:test_minimal_reproduction.py:62 Before wait()
      INFO     test_minimal_reproduction:test_minimal_reproduction.py:64 After wait()
      PASSED                                                                   [100%]QThread: Destroyed while thread is still running
      

      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
              timmwagener Timm Wagener
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes