##// END OF EJS Templates
Merge pull request #1008 from minrk/excepthook...
Fernando Perez -
r5348:493f6d4b merge
parent child Browse files
Show More
@@ -137,6 +137,11 b' class BaseIPythonApplication(Application):'
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 b' class BaseIPythonApplication(Application):'
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)
@@ -21,9 +21,11 b' Authors:'
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 b' To ensure accurate tracking of this issue, please file a report about it at:'
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 b' class CrashHandler(object):'
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 b' class CrashHandler(object):'
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
@@ -81,8 +81,8 b' 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 b' class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):'
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"""
@@ -58,8 +58,8 b' 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 )
@@ -780,6 +780,7 b' class IPKernelApp(KernelApp, InteractiveShellApp):'
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 #-----------------------------------------------------------------------------
General Comments 0
You need to be logged in to leave comments. Login now