Skip to content
This repository

don't use crash_handler by default #1008

Merged
merged 3 commits into from over 2 years ago

2 participants

Min RK Fernando Perez
Min RK
Owner

Now the excepthook shows a regular traceback, with a brief message about reporting bugs and how to enable to the big crash handler. Adding a more/0 to interact inside if more:, I get:

In [1]: if 1:
Traceback (most recent call last):
  File "/prefix/bin/ipython", line 9, in <module>
    load_entry_point('ipython==0.12.dev', 'console_scripts', 'ipython')()
  File "/prefix/IPython/frontend/terminal/ipapp.py", line 393, in launch_new_instance
    app.start()
  File "/prefix/IPython/frontend/terminal/ipapp.py", line 367, in start
    self.shell.mainloop()
  File "/prefix/IPython/frontend/terminal/interactiveshell.py", line 220, in mainloop
    self.interact(display_banner=display_banner)
  File "/prefix/IPython/frontend/terminal/interactiveshell.py", line 288, in interact
    more/0
ZeroDivisionError: integer division or modulo by zero

If you suspect this is an IPython bug, please report it at:
    https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@scipy.org

You can enable a much more verbose crash handler with:
    %config Application.verbose_crash=True

small fixes along the way:

  • current Application added to configurables list, for use in %config.
  • email addresses in full crash reports changed to ipython-dev, so they don't go straight to individual users.

Should close #695, and ameliorate #833 (doesn't fix the bug, but the message is more sensible)

added some commits November 17, 2011
Min RK include parent Application in InteractiveShell.configurables
for use in %config magic
69c13a1
Min RK use ipython-dev as the email address for crash reports a6e5b20
Min RK Don't use crash_handler by default
adds crash_handler_lite for adding a short message after a regular
traceback.

Application.verbose_crash configurable determines which to use
bb6f87b
Fernando Perez
Owner

Great! Code looks clean, tested it. Nice to get rid of those endless crash reports... Merging now.

Fernando Perez fperez merged commit 493f6d4 into from November 20, 2011
Fernando Perez fperez closed this November 20, 2011
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 3 unique commits by 1 author.

Nov 17, 2011
Min RK include parent Application in InteractiveShell.configurables
for use in %config magic
69c13a1
Min RK use ipython-dev as the email address for crash reports a6e5b20
Min RK Don't use crash_handler by default
adds crash_handler_lite for adding a short message after a regular
traceback.

Application.verbose_crash configurable determines which to use
bb6f87b
This page is out of date. Refresh to see the latest.
21  IPython/core/application.py
@@ -137,6 +137,11 @@ def _config_files_default(self):
137 137
         profile, then they will be staged into the new directory.  Otherwise,
138 138
         default config files will be automatically generated.
139 139
         """)
  140
+    
  141
+    verbose_crash = Bool(False, config=True,
  142
+        help="""Create a massive crash report when IPython enconters what may be an
  143
+        internal error.  The default is to append a short message to the
  144
+        usual traceback""")
140 145
 
141 146
     # The class to use as the crash handler.
142 147
     crash_handler_class = Type(crashhandler.CrashHandler)
@@ -154,11 +159,23 @@ def __init__(self, **kwargs):
154 159
     def init_crash_handler(self):
155 160
         """Create a crash handler, typically setting sys.excepthook to it."""
156 161
         self.crash_handler = self.crash_handler_class(self)
157  
-        sys.excepthook = self.crash_handler
  162
+        sys.excepthook = self.excepthook
158 163
         def unset_crashhandler():
159 164
             sys.excepthook = sys.__excepthook__
160 165
         atexit.register(unset_crashhandler)
161  
-
  166
+    
  167
+    def excepthook(self, etype, evalue, tb):
  168
+        """this is sys.excepthook after init_crashhandler
  169
+        
  170
+        set self.verbose_crash=True to use our full crashhandler, instead of
  171
+        a regular traceback with a short message (crash_handler_lite)
  172
+        """
  173
+        
  174
+        if self.verbose_crash:
  175
+            return self.crash_handler(etype, evalue, tb)
  176
+        else:
  177
+            return crashhandler.crash_handler_lite(etype, evalue, tb)
  178
+    
162 179
     def _ipython_dir_changed(self, name, old, new):
163 180
         if old in sys.path:
164 181
             sys.path.remove(old)
27  IPython/core/crashhandler.py
@@ -21,9 +21,11 @@
21 21
 
22 22
 import os
23 23
 import sys
  24
+import traceback
24 25
 from pprint import pformat
25 26
 
26 27
 from IPython.core import ultratb
  28
+from IPython.core.release import author_email
27 29
 from IPython.utils.sysinfo import sys_info
28 30
 
29 31
 #-----------------------------------------------------------------------------
@@ -54,6 +56,15 @@
54 56
 {bug_tracker}
55 57
 """
56 58
 
  59
+_lite_message_template = """
  60
+If you suspect this is an IPython bug, please report it at:
  61
+    https://github.com/ipython/ipython/issues
  62
+or send an email to the mailing list at {email}
  63
+
  64
+You can enable a much more verbose traceback with:
  65
+    {config}Application.verbose_crash=True
  66
+"""
  67
+
57 68
 
58 69
 class CrashHandler(object):
59 70
     """Customizable crash handlers for IPython applications.
@@ -161,7 +172,7 @@ def __call__(self, etype, evalue, etb):
161 172
         # Construct report on disk
162 173
         report.write(self.make_report(traceback))
163 174
         report.close()
164  
-        raw_input("Hit <Enter> to quit this message (your terminal may close):")
  175
+        raw_input("Hit <Enter> to quit (your terminal may close):")
165 176
 
166 177
     def make_report(self,traceback):
167 178
         """Return a string containing a crash report."""
@@ -184,3 +195,17 @@ def make_report(self,traceback):
184 195
 
185 196
         return ''.join(report)
186 197
 
  198
+
  199
+def crash_handler_lite(etype, evalue, tb):
  200
+    """a light excepthook, adding a small message to the usual traceback"""
  201
+    traceback.print_exception(etype, evalue, tb)
  202
+    
  203
+    from IPython.core.interactiveshell import InteractiveShell
  204
+    if InteractiveShell.initialized():
  205
+        # we are in a Shell environment, give %magic example
  206
+        config = "%config "
  207
+    else:
  208
+        # we are not in a shell, show generic config
  209
+        config = "c."
  210
+    print >> sys.stderr, _lite_message_template.format(email=author_email, config=config)
  211
+
5  IPython/frontend/terminal/ipapp.py
@@ -81,8 +81,8 @@ class IPAppCrashHandler(CrashHandler):
81 81
 
82 82
     def __init__(self, app):
83 83
         contact_name = release.authors['Fernando'][0]
84  
-        contact_email = release.authors['Fernando'][1]
85  
-        bug_tracker = 'http://github.com/ipython/ipython/issues'
  84
+        contact_email = release.author_email
  85
+        bug_tracker = 'https://github.com/ipython/ipython/issues'
86 86
         super(IPAppCrashHandler,self).__init__(
87 87
             app, contact_name, contact_email, bug_tracker
88 88
         )
@@ -320,6 +320,7 @@ def init_shell(self):
320 320
         self.shell = TerminalInteractiveShell.instance(config=self.config,
321 321
                         display_banner=False, profile_dir=self.profile_dir,
322 322
                         ipython_dir=self.ipython_dir)
  323
+        self.shell.configurables.append(self)
323 324
 
324 325
     def init_banner(self):
325 326
         """optionally display the banner"""
4  IPython/parallel/apps/baseapp.py
@@ -58,8 +58,8 @@ class ParallelCrashHandler(CrashHandler):
58 58
 
59 59
     def __init__(self, app):
60 60
         contact_name = release.authors['Min'][0]
61  
-        contact_email = release.authors['Min'][1]
62  
-        bug_tracker = 'http://github.com/ipython/ipython/issues'
  61
+        contact_email = release.author_email
  62
+        bug_tracker = 'https://github.com/ipython/ipython/issues'
63 63
         super(ParallelCrashHandler,self).__init__(
64 64
             app, contact_name, contact_email, bug_tracker
65 65
         )
1  IPython/zmq/ipkernel.py
@@ -780,6 +780,7 @@ def print_tb(etype, evalue, stb):
780 780
 
781 781
     def init_shell(self):
782 782
         self.shell = self.kernel.shell
  783
+        self.shell.configurables.append(self)
783 784
 
784 785
 
785 786
 #-----------------------------------------------------------------------------
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.