Skip to content
This repository

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 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 November 10, 2011
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 November 10, 2011
Min RK 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 January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 10, 2011
Min RK 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 24 additions and 5 deletions. Show diff stats Hide diff stats

  1. 29  IPython/zmq/ipkernel.py
29  IPython/zmq/ipkernel.py
@@ -743,9 +743,6 @@ def initialize(self, argv=None):
743 743
 
744 744
     def init_kernel(self):
745 745
 
746  
-        if self.pylab:
747  
-            gui, backend = pylabtools.find_gui_and_backend(self.pylab)
748  
-
749 746
         kernel = Kernel(config=self.config, session=self.session,
750 747
                                 shell_socket=self.shell_socket,
751 748
                                 iopub_socket=self.iopub_socket,
@@ -755,9 +752,31 @@ def init_kernel(self):
755 752
         )
756 753
         self.kernel = kernel
757 754
         kernel.record_ports(self.ports)
758  
-
  755
+        shell = kernel.shell
759 756
         if self.pylab:
760  
-            kernel.shell.enable_pylab(gui, import_all=self.pylab_import_all)
  757
+            try:
  758
+                gui, backend = pylabtools.find_gui_and_backend(self.pylab)
  759
+                shell.enable_pylab(gui, import_all=self.pylab_import_all)
  760
+            except Exception:
  761
+                self.log.error("Pylab initialization failed", exc_info=True)
  762
+                # print exception straight to stdout, because normally 
  763
+                # _showtraceback associates the reply with an execution, 
  764
+                # which means frontends will never draw it, as this exception 
  765
+                # is not associated with any execute request.
  766
+                
  767
+                # replace pyerr-sending traceback with stdout
  768
+                _showtraceback = shell._showtraceback
  769
+                def print_tb(etype, evalue, stb):
  770
+                    print ("Error initializing pylab, pylab mode will not be active", file=io.stderr)
  771
+                    print (shell.InteractiveTB.stb2text(stb), file=io.stdout)
  772
+                shell._showtraceback = print_tb
  773
+                
  774
+                # send the traceback over stdout
  775
+                shell.showtraceback(tb_offset=0)
  776
+                
  777
+                # restore proper _showtraceback method
  778
+                shell._showtraceback = _showtraceback
  779
+                
761 780
 
762 781
     def init_shell(self):
763 782
         self.shell = self.kernel.shell
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.