Skip to content

Loading…

Show traceback, continuing to start kernel if pylab init fails #991

Closed
wants to merge 1 commit into from

3 participants

@minrk
IPython member

Error message goes directly over stderr (and traceback over stdout),
rather than as a pyerr message, which is associated with a particular
frontend, and thus ignored because startup actions were not requested
by anyone.

This better matches the terminal behavior, where ipython --pylab without matplotlib
installed shows a traceback, but continues to start.

In the qtconsole the traceback will come in below the banner, but in the notebook
the message will not arrive until after the first execution.

closes gh-990

@minrk minrk Show traceback, continuing to start kernel if pylab init fails
Error message goes directly over stderr (and traceback over stdout),
rather than as a pyerr message, which is associated with a particular
frontend, and thus ignored because startup actions were not requested
by anyone.

This better matches the terminal behavior, where `ipython --pylab` without matplotlib
installed shows a traceback, but continues to start.

In the qtconsole the traceback will come in below the banner, but in the notebook
the message will not arrive until after the first execution.

closes gh-990
ba9389a
@fperez
IPython member

Yup, looks great, thanks. Will rebase now to avoid recursive merge on just one commit and will merge.

@fperez
IPython member

MMh, auto-close seems not to be working... Closed by ec0c00d

@fperez fperez closed this
@minrk
IPython member

When you rebase and merge (identical to cherry-pick), autoclose doesn't work, because the hash changes.

@fperez
IPython member

No, but I amended the commit message and manually included a closes gh-991 precisely for that reason. So it should have auto-closed because of my message.

@minrk
IPython member

ah, that's definitely strange. Maybe they don't work if you put more than one on a line? I've always been in the habit of one-line per magic directive.

@fperez
IPython member

I don't think it's that, the same thing happened just now with 3830949, and that was just one on a line. I still had to close it manually, their auto-closing is definitely acting up.

@minrk
IPython member

Right - and there should at least be those 'mentioned in commit' backrefs, even if the magic closing doesn't happen. I guess their commit hook processing is down/backed up right now.

@fperez
IPython member

yup, looks like it.

@thisch

Great, works as described in the commit msg! however, the solution for the notebook is not the best. I think that putting more effort into it is not necessary (atm) .

@mdboom mdboom pushed a commit to mdboom/ipython that referenced this pull request
@minrk minrk Show traceback, continuing to start kernel if pylab init fails
Error message goes directly over stderr (and traceback over stdout),
rather than as a pyerr message, which is associated with a particular
frontend, and thus ignored because startup actions were not requested
by anyone.

This better matches the terminal behavior, where `ipython --pylab` without matplotlib
installed shows a traceback, but continues to start.

In the qtconsole the traceback will come in below the banner, but in the notebook
the message will not arrive until after the first execution.

closes gh-990, closes gh-991.
ec0c00d
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request
@minrk minrk Show traceback, continuing to start kernel if pylab init fails
Error message goes directly over stderr (and traceback over stdout),
rather than as a pyerr message, which is associated with a particular
frontend, and thus ignored because startup actions were not requested
by anyone.

This better matches the terminal behavior, where `ipython --pylab` without matplotlib
installed shows a traceback, but continues to start.

In the qtconsole the traceback will come in below the banner, but in the notebook
the message will not arrive until after the first execution.

closes gh-990, closes gh-991.
8a84deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 10, 2011
  1. @minrk

    Show traceback, continuing to start kernel if pylab init fails

    minrk committed
    Error message goes directly over stderr (and traceback over stdout),
    rather than as a pyerr message, which is associated with a particular
    frontend, and thus ignored because startup actions were not requested
    by anyone.
    
    This better matches the terminal behavior, where `ipython --pylab` without matplotlib
    installed shows a traceback, but continues to start.
    
    In the qtconsole the traceback will come in below the banner, but in the notebook
    the message will not arrive until after the first execution.
    
    closes gh-990
Showing with 24 additions and 5 deletions.
  1. +24 −5 IPython/zmq/ipkernel.py
View
29 IPython/zmq/ipkernel.py
@@ -743,9 +743,6 @@ def initialize(self, argv=None):
def init_kernel(self):
- if self.pylab:
- gui, backend = pylabtools.find_gui_and_backend(self.pylab)
-
kernel = Kernel(config=self.config, session=self.session,
shell_socket=self.shell_socket,
iopub_socket=self.iopub_socket,
@@ -755,9 +752,31 @@ def init_kernel(self):
)
self.kernel = kernel
kernel.record_ports(self.ports)
-
+ shell = kernel.shell
if self.pylab:
- kernel.shell.enable_pylab(gui, import_all=self.pylab_import_all)
+ try:
+ gui, backend = pylabtools.find_gui_and_backend(self.pylab)
+ shell.enable_pylab(gui, import_all=self.pylab_import_all)
+ except Exception:
+ self.log.error("Pylab initialization failed", exc_info=True)
+ # print exception straight to stdout, because normally
+ # _showtraceback associates the reply with an execution,
+ # which means frontends will never draw it, as this exception
+ # is not associated with any execute request.
+
+ # replace pyerr-sending traceback with stdout
+ _showtraceback = shell._showtraceback
+ def print_tb(etype, evalue, stb):
+ print ("Error initializing pylab, pylab mode will not be active", file=io.stderr)
+ print (shell.InteractiveTB.stb2text(stb), file=io.stdout)
+ shell._showtraceback = print_tb
+
+ # send the traceback over stdout
+ shell.showtraceback(tb_offset=0)
+
+ # restore proper _showtraceback method
+ shell._showtraceback = _showtraceback
+
def init_shell(self):
self.shell = self.kernel.shell
Something went wrong with that request. Please try again.