Details
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
- relates to
-
PYSIDE-2321 Exceptions raised from event handlers cause the traceback module to crash
- Closed