Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some exceptions are not shown in qtconsole #6509

Open
ccordoba12 opened this issue Sep 20, 2014 · 5 comments
Open

Some exceptions are not shown in qtconsole #6509

ccordoba12 opened this issue Sep 20, 2014 · 5 comments
Milestone

Comments

@ccordoba12
Copy link
Member

The following code (preceded by a %gui qt) doesn't print a NameError exception in qtconsole every time fun is called. Instead it's printed in the terminal where it was started:

from PyQt4.QtCore import QTimer

def fun():
    print "there will be an exception after this"
    a

timer = QTimer()
timer.start(1000)
timer.timeout.connect(fun)

What is the reason for this?

@minrk
Copy link
Member

minrk commented Sep 21, 2014

I think PyQt registers its own except hook for exceptions raised in Qt callbacks.

@josselex
Copy link

josselex commented Nov 7, 2014

But why are these exceptions then shown in the terminal and not in the console? (And can I route this somehow to the console?)

@minrk
Copy link
Member

minrk commented Nov 7, 2014

But why are these exceptions then shown in the terminal and not in the console?

Because it is the sys.excepthook registered by IPython that sends the traceback to the frontend. Since the IPython excepthook doesn't get called, the traceback is drawn to the terminal, which is the default behavior.

@minrk minrk added this to the wishlist milestone Nov 7, 2014
@josselex
Copy link

Ok. Now i'm trying to ouput the error to the frontend. But It does not work, when called from QT:

import IPython,sys,PyQt4
#%% function to print the last exception
def print_excep():
    print "print_excep"
    IPython.get_ipython().showtraceback()
#%% make an exception
a
#%% this works
print_excep()
#%% called "from Qt" this does not work
PyQt4.QtCore.QTimer.singleShot(1000,print_excep)

"print_excep" gets output on the console, but not the traceback

@josselex
Copy link

I do this because I want to do the following to get it work to print errors from qt:

def print_excep(etype,evalue,tb):
    print "print_excep"
    IPython.get_ipython().showtraceback()
#%% register an excepthook for qt. 
#%% I don't know why it only works when called from the qt event loop
def prepare_excepthook():
    sys.excepthook = print_excep    
PyQt4.QtCore.QTimer.singleShot(0,prepare_excepthook)
#%% produce an error from qt event loop
def error_in_func():
    a
PyQt4.QtCore.QTimer.singleShot(0,error_in_func)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants