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

Exceptions are suppressed when thrown by a zero-delay single-shot timer

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • 6.7.2, 6.8.0
    • 6.7.0
    • PySide
    • None
    • Python 3.12
    • Windows
    • 36e2078d2 (dev), 060d38526 (6.7)

    Description

      When a function, queued by a zero-delay single-shot timer throws an exception, the exception is silently ignored but will cause other problems down the line.

      This problem disappears by adding just 1ms delay to the timer.

      See the following example:

      from PySide6.QtCore import QTimer
      from PySide6.QtWidgets import QApplication
      from PySide6.QtWidgets import QPushButton
      from PySide6.QtWidgets import QVBoxLayout
      from PySide6.QtWidgets import QWidget
      
      def fail():
          raise Exception("FAIL!")
      
      app = QApplication()
      b1 = QPushButton("FAIL now")
      b1.clicked.connect(fail)
      b2 = QPushButton("FAIL soon")
      b2.clicked.connect(lambda: QTimer.singleShot(0, fail))
      b3 = QPushButton("FAIL later")
      b3.clicked.connect(lambda: QTimer.singleShot(1, fail))
      
      widget = QWidget()
      layout = QVBoxLayout(widget)
      layout.addWidget(b1)
      layout.addWidget(b2)
      layout.addWidget(b3)
      
      widget.show()
      app.exec()
      

      Clicking FAIL now or FAIL later will raise an exception as expected:

      Traceback (most recent call last):
        File "c:\_WIP_\exceptions.py", line 8, in fail
          raise Exception("FAIL!")
      Exception: FAIL!
      

      Clicking FAIL soon once will not show any exception.

      Clicking FAIL soon again will show the following traceback:

      Traceback (most recent call last):
        File "c:\_WIP_\exceptions.py", line 8, in fail
          raise Exception("FAIL!")
      Exception: FAIL!
      c:\_WIP_\exceptions.py:14: RuntimeWarning: libshiboken: Overflow: Value 0 exceeds limits of type  [signed] "int" (4bytes).
        b2.clicked.connect(lambda: QTimer.singleShot(0, fail))
      Traceback (most recent call last):
        File "c:\_WIP_\exceptions.py", line 14, in <lambda>
          b2.clicked.connect(lambda: QTimer.singleShot(0, fail))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
      OverflowError
      

      Clicking FAIL now or FAIL later after the first click on FAIL soon will show a different traceback.

      Attachments

        Issue Links

          For Gerrit Dashboard: PYSIDE-2745
          # Subject Branch Project Status CR V

          Activity

            People

              adherrma Adrian Herrmann (Inactive)
              maxxpower Markus Fleischhacker
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes