Exceptions in PyQt event loop and ipython · Issue #10057 · ipython/ipython (original) (raw)

I am not sure if this is really a bug, but rather an issue that I am facing with ipython and option qt. My problem was also posted 2 days ago on Stackoverflow (http://stackoverflow.com/questions/40608610/exceptions-in-pyqt-event-loop-and-ipython). If the problem turns out to be solvable, ideally, it would be nice to have a quick fix for now (which function to monkey patch?). Then, maybe a more permanent fix can be included in future releases.

I have a PyQt program that is displaying some widgets and buttons.

I want the program to run either as a standalone python instance, or inside an ipython environment. In this case, I use the following magic command in Jupyter console (formerly I had to use --gui=qt when launching the ipython qtconsole)

In order to have a program that works both ways, my main module has the following lines:

APP = QtGui.Qapplication.instance() # retrieves the ipython qt application if any
if APP is None:
    APP = QtGui.QApplication(["foo"]) # create one if standalone execution

if __name__=='__main__':
    APP.exec_() # Launch the event loop here in standalone mode 

Here is my problem: exceptions generated by the event loop are very hard to detect by the user because they pop-out in the background console. I would like to catch any exception occuring in the event loop, and display a warning (for intance in the QMainWindow status bar to make the user aware that an exception occured).

I have tried several strategies, but there seems to be a conspiracy between PyQt's and Ipython's internal machineries to make this impossible:

It is a problem that keeps bothering me since a long time. Does anyone have a solution?