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

REG->6.4.0-: QMetaObject.invokeMethod(BlockingQueuedConnection) causes deadlock

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P1: Critical P1: Critical
    • None
    • 6.4.0
    • PySide, Shiboken
    • None
    • Linux, windows
    • Linux/X11, Windows
    • d106f5811c (pyside/pyside-setup/dev) 52e493335d (pyside/pyside-setup/6.4) 52e493335d (pyside/tqtc-pyside-setup/6.4) d106f5811c (pyside/tqtc-pyside-setup/dev) d106f5811c (pyside/tqtc-pyside-setup/tqtc/dev) 52e493335d (pyside/pyside-setup/6.4.1)

      The following python program leads to a deadlock since pyside 6.4.0:

      import threading
      from sys import argv
      from threading import Thread
      
      from PySide6.QtCore import QMetaObject
      from PySide6.QtCore import Qt
      from PySide6.QtCore import Slot
      from PySide6.QtWidgets import QApplication
      from PySide6.QtWidgets import QLabel
      from PySide6.QtWidgets import QMainWindow
      
      class Window(QMainWindow):
        def __init__(self):
          super().__init__()
          print(f"__init__: {threading.current_thread().name}")
          self.__statusLabel = QLabel()
          self.statusBar().addWidget(self.__statusLabel)
      
        @Slot()
        def setText(self):
          print(f"setText: {threading.current_thread().name}")
          self.__statusLabel.setText("Status")
      
        def setStatus(self):
          print(f"setStatus: {threading.current_thread().name}")
          QMetaObject.invokeMethod(self, "setText", Qt.ConnectionType.BlockingQueuedConnection)
      
      
      def asynch(window):
        print(f"asynch: {threading.current_thread().name}")
        window.setStatus()
      
      app = QApplication(argv)
      window = Window()
      Thread(target=asynch, args=[window], daemon=True).start()
      window.show()
      app.exec()
      

      While asynch() and setStatus() are called on a new Thread-1, setText() should be called on the MainThread.

      This worked fine with Pyside6 6.3.1:

      $ python asyncapp.py  
      __init__: MainThread
      asynch: Thread-1 (asynch)
      setStatus: Thread-1 (asynch)
      setText: MainThread
      

       With Pyside6 6.4.0 I have a deadlock:

      $ python asyncapp.py  
      __init__: MainThread
      asynch: Thread-1 (asynch)
      setStatus: Thread-1 (asynch)
      

       

        1. asyncapp.py
          1 kB
        2. pyside2121.py
          1 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            kleint Friedemann Kleint
            wolf.seifert Wolfgang Seifert
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes