Reclaim sys.excepthook for interactive shell in %gui qt by tlambert03 · Pull Request #12842 · ipython/ipython (original) (raw)
Currently, if someone uses the %gui qt
magic, and an exception occurs in the event loop, it gets rendered with an unformatted traceback. This appears to be because sys.excepthook is being restored back to BaseIPythonApplication.excepthook
before the Qt event loop is run (see #10057 (comment)). To see this, run the following gui in an ipython --gui qt
session:
from qtpy.QtWidgets import QPushButton
def _raise(): raise ValueError("clicked")
b = QPushButton("hi") b.clicked.connect(_raise) b.show() # and click the button for traceback
Following this tip, this PR schedules a callback to restore sys.excepthook
back to the InteractiveShell.excepthook
immediately after the event loop starts.