Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

3 participants

Min RK Fernando Perez Thomas Hisch
Min RK
Owner

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

Min RK 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
Fernando Perez
Owner

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

Fernando Perez
Owner

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

Fernando Perez fperez closed this
Min RK
Owner

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

Fernando Perez
Owner

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.

Min RK
Owner

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.

Fernando Perez
Owner

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.

Min RK
Owner

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.

Fernando Perez
Owner

yup, looks like it.

Thomas Hisch

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) .

Michael Droettboom mdboom referenced this pull request from a commit in mdboom/ipython
Min RK 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
Fernando Perez fperez referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
matthew von rocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
Min RK 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. Min RK

    Show traceback, continuing to start kernel if pylab init fails

    minrk authored
    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
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 5 deletions.
  1. +24 −5 IPython/zmq/ipkernel.py
29 IPython/zmq/ipkernel.py
View
@@ -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.