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

Inconsistent, unsuppressable "Failed to disconnect" RuntimeErrors

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.8.0, 6.7.1
    • 6.7.0
    • PySide
    • None
    • Windows 11 23H2
    • Windows
    • c97b67f01 (dev), 7304b26c2 (6.7)

    Description

      This tickets arose out of https://github.com/pytest-dev/pytest-qt/issues/552.

      There is a number of issues new in 6.7.0 revolving around warnings when disconnecting signals.

      1. This code prints warnings that cannot be suppressed in Python:

      import warnings
      from PySide6.QtCore import Signal
      from PySide6.QtWidgets import QApplication, QMainWindow
      
      warnings.filterwarnings('ignore')
      
      class Window(QMainWindow):
          signal = Signal()
      
          def __init__(self):
              super().__init__()
              self.signal.connect(self.Slot)
              self.signal.disconnect(self.Slot)
              self.signal.disconnect(self.Slot)
      
          def Slot(self): ...
      
      warnings.warn(Warning("some warning"))
      app = QApplication()
      window = Window()
      print("Done")
      

      2. This code shows that the warnings appear somewhat inconsistently. Run this code several times, and you will see the warning 1 or 2 times. If you see it only once, increase "10"; if you see it only twice, decrease "10":

      from PySide6.QtCore import QTimer
      from PySide6.QtWidgets import QApplication
      
      class MyClass:
          def __init__(self):
              self.timer = QTimer()
              self.timer.timeout.disconnect(self.empty)
      
          def empty(self): ...
      
      app = QApplication()
      for _ in range(10):
          MyClass()
      

      3. This code shows that the warnings appears depending on whether the reference to the MyClass object is stored in a variable or not:

      from PySide6.QtCore import QTimer
      from PySide6.QtWidgets import QApplication, QWidget
      
      class MyClass:
          def __init__(self, signal):
              self.timer = QTimer()
              signal.connect(self.cleanup)
      
          def cleanup(self):
              self.timer.timeout.disconnect(self.cleanup)
      
      app = QApplication()
      widget = QWidget()
      signal = widget.windowTitleChanged
      
      print("- no warning:")
      MyClass(signal)
      signal.emit("")
      
      print("- warning:")
      _class = MyClass(signal)
      signal.emit("")
      

      Attachments

        1. pyside2705_1.py
          0.7 kB
          Friedemann Kleint
        2. pyside2705_2.py
          0.5 kB
          Friedemann Kleint
        3. pyside2705_3.py
          0.7 kB
          Friedemann Kleint
        4. pyside2705_diag.diff
          1.0 kB
          Friedemann Kleint
        5. pyside2705_log.txt
          2 kB
          Friedemann Kleint

        Issue Links

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

          Activity

            People

              kleint Friedemann Kleint
              bers bers bers
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes