##// END OF EJS Templates
Move dict keys completions higher....
Move dict keys completions higher. If we are in a dict this is likely way more accurate.

File last commit:

r26491:baf253a1
r27063:d23958a1
Show More
crashhandler.py
223 lines | 8.1 KiB | text/x-python | PythonLexer
Brian Granger
More work on the crash handler....
r2506 # encoding: utf-8
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 """sys.excepthook for IPython itself, leaves a detailed report on disk.
Fernando Perez
Update copyright/author statements....
r1875
Brian Granger
More work on the crash handler....
r2506 Authors:
Fernando Perez
Update copyright/author statements....
r1875
Brian Granger
More work on the crash handler....
r2506 * Fernando Perez
* Brian E. Granger
Fernando Perez
Remove svn-style $Id marks from docstrings and Release imports....
r1853 """
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Brian Granger
More work on the crash handler....
r2506 #-----------------------------------------------------------------------------
# Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
Brian Granger
More work on the crash handler....
r2506 #-----------------------------------------------------------------------------
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Brian Granger
More work on the crash handler....
r2506 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
fperez
Cosmetic cleanups: put all imports in a single line, and sort them...
r52 import os
import sys
MinRK
Don't use crash_handler by default...
r5317 import traceback
Brian Granger
ColorANSI.py -> utils/coloransi.py and all imports updated.
r2010 from pprint import pformat
PhanatosZou
use pathlib in crashhandler
r26319 from pathlib import Path
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Brian Granger
ultraTB.py => core/ultratb.py and imports updated.
r2048 from IPython.core import ultratb
MinRK
Don't use crash_handler by default...
r5317 from IPython.core.release import author_email
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 from IPython.utils.sysinfo import sys_info
Srinivas Reddy Thatiparthy
rename py3compat.getcwd() -> os.getcwd()
r23046 from IPython.utils.py3compat import input
Fernando Perez
Moved system info into its own utility, so we can use in in test suite too.
r2495
Matthias Bussonnier
print the version on crash
r25284 from IPython.core.release import __version__ as version
Brian Granger
More work on the crash handler....
r2506 #-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
Fernando Perez
Update copyright/author statements....
r1875
Brian Granger
More work on the crash handler....
r2506 # Template for the user message.
_default_message_template = """\
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 Oops, {app_name} crashed. We do our best to make it stable, but...
Fernando Perez
Moved system info into its own utility, so we can use in in test suite too.
r2495
Brian Granger
More work on the crash handler....
r2506 A crash report was automatically generated with the following information:
- A verbatim copy of the crash traceback.
- A copy of your input history during this session.
chebee7i
Fix templates for CrashHandler....
r4382 - Data on your current {app_name} configuration.
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Brian Granger
More work on the crash handler....
r2506 It was left in the file named:
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 \t'{crash_report_fname}'
Brian Granger
More work on the crash handler....
r2506 If you can email this file to the developers, the information in it will help
Samuel Lelièvre
Improve instructions on reporting crash...
r24185 them in understanding and correcting the problem.
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
chebee7i
Fix templates for CrashHandler....
r4382 You can mail it to: {contact_name} at {contact_email}
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 with the subject '{app_name} Crash Report'.
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 If you want to do it now, the following command will work (under Unix):
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 mail -s '{app_name} Crash Report' {contact_email} < {crash_report_fname}
Brian Granger
More work on the crash handler....
r2506
Samuel Lelièvre
Make crash handler tell users to email more detail...
r24189 In your email, please also include information about:
- The operating system under which the crash happened: Linux, macOS, Windows,
other, and which exact version (for example: Ubuntu 16.04.3, macOS 10.13.2,
Windows 10 Pro), and whether it is 32-bit or 64-bit;
- How {app_name} was installed: using pip or conda, from GitHub, as part of
a Docker container, or other, providing more detail if possible;
- How to reproduce the crash: what exact sequence of instructions can one
input to get the same crash? Ideally, find a minimal yet complete sequence
of instructions that yields the crash.
Samuel Lelièvre
Improve instructions on reporting crash...
r24185
Brian Granger
More work on the crash handler....
r2506 To ensure accurate tracking of this issue, please file a report about it at:
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 {bug_tracker}
Brian Granger
More work on the crash handler....
r2506 """
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
MinRK
Don't use crash_handler by default...
r5317 _lite_message_template = """
Matthias Bussonnier
print the version on crash
r25284 If you suspect this is an IPython {version} bug, please report it at:
MinRK
Don't use crash_handler by default...
r5317 https://github.com/ipython/ipython/issues
or send an email to the mailing list at {email}
Fernando Perez
Improve user message in lightweight crash handler.
r5349 You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
MinRK
Don't use crash_handler by default...
r5317 {config}Application.verbose_crash=True
"""
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 class CrashHandler(object):
"""Customizable crash handlers for IPython applications.
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 Instances of this class provide a :meth:`__call__` method which can be
used as a ``sys.excepthook``. The :meth:`__call__` signature is::
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 def __call__(self, etype, evalue, etb)
"""
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 message_template = _default_message_template
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 section_sep = '\n\n'+'*'*75+'\n\n'
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Bernardo B. Marques
remove all trailling spaces
r4872 def __init__(self, app, contact_name=None, contact_email=None,
Brian Granger
More work on the crash handler....
r2506 bug_tracker=None, show_crash_traceback=True, call_pdb=False):
"""Create a new crash handler
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381
Brian Granger
More work on the crash handler....
r2506 Parameters
----------
Matthias Bussonnier
DOC: Some more autoformatting of docstrings....
r26491 app : Application
Bernardo B. Marques
remove all trailling spaces
r4872 A running :class:`Application` instance, which will be queried at
Brian Granger
More work on the crash handler....
r2506 crash time for internal information.
contact_name : str
A string with the name of the person to contact.
contact_email : str
A string with the email address of the contact.
bug_tracker : str
A string with the URL for your project's bug tracker.
show_crash_traceback : bool
If false, don't print the crash traceback on stderr, only generate
the on-disk report
Matthias Bussonnier
DOC: Some more autoformatting of docstrings....
r26491 Non-argument instance attributes
Brian Granger
More work on the crash handler....
r2506 These instances contain some non-argument attributes which allow for
further customization of the crash handler's behavior. Please see the
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 source for further details.
"""
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 self.crash_report_fname = "Crash_report_%s.txt" % app.name
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 self.app = app
Fernando Perez
Added ability to invoke pdb on IPython crashes....
r2437 self.call_pdb = call_pdb
#self.call_pdb = True # dbg
Thomas Kluyver
Use str.format instead of Itpl in crash handler.
r4049 self.show_crash_traceback = show_crash_traceback
self.info = dict(app_name = app.name,
contact_name = contact_name,
contact_email = contact_email,
bug_tracker = bug_tracker,
crash_report_fname = self.crash_report_fname)
Bernardo B. Marques
remove all trailling spaces
r4872
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Brian Granger
More work on the crash handler....
r2506 def __call__(self, etype, evalue, etb):
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 """Handle an exception, call for compatible with sys.excepthook"""
MinRK
unregister crash handler on call...
r5173
# do not allow the crash handler to be called twice without reinstalling it
# this prevents unlikely errors in the crash handling from entering an
# infinite loop.
sys.excepthook = sys.__excepthook__
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 # Report tracebacks shouldn't use color in general (safer for users)
color_scheme = 'NoColor'
# Use this ONLY for developer debugging (keep commented out for release)
#color_scheme = 'Linux' # dbg
try:
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 rptdir = self.app.ipython_dir
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 except:
PhanatosZou
use pathlib in crashhandler
r26319 rptdir = Path.cwd()
if rptdir is None or not Path.is_dir(rptdir):
rptdir = Path.cwd()
report_name = rptdir / self.crash_report_fname
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 # write the report filename into the instance dict so it can get
# properly expanded out in the user message template
self.crash_report_fname = report_name
chebee7i
Fix templates for CrashHandler....
r4382 self.info['crash_report_fname'] = report_name
Brian Granger
More work on the crash handler....
r2506 TBhandler = ultratb.VerboseTB(
color_scheme=color_scheme,
long_header=1,
call_pdb=self.call_pdb,
)
Fernando Perez
Added ability to invoke pdb on IPython crashes....
r2437 if self.call_pdb:
TBhandler(etype,evalue,etb)
return
else:
traceback = TBhandler.text(etype,evalue,etb,context=31)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# print traceback to screen
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 if self.show_crash_traceback:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(traceback, file=sys.stderr)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
# and generate a complete report on disk
try:
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 report = open(report_name,'w')
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 except:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('Could not create crash report on disk.', file=sys.stderr)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0 return
Mickaël Schoentgen
Fix ResourceWarning: unclosed file...
r24897 with report:
# Inform user on stderr of what happened
print('\n'+'*'*70+'\n', file=sys.stderr)
print(self.message_template.format(**self.info), file=sys.stderr)
# Construct report on disk
report.write(self.make_report(traceback))
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
Thomas Kluyver
Fix references to raw_input()
r13355 input("Hit <Enter> to quit (your terminal may close):")
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 def make_report(self,traceback):
"""Return a string containing a crash report."""
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 sec_sep = self.section_sep
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Moved system info into its own utility, so we can use in in test suite too.
r2495 report = ['*'*75+'\n\n'+'IPython post-mortem report\n\n']
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 rpt_add = report.append
Fernando Perez
Moved system info into its own utility, so we can use in in test suite too.
r2495 rpt_add(sys_info())
Bernardo B. Marques
remove all trailling spaces
r4872
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 try:
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 config = pformat(self.app.config)
Brian Granger
More work on the crash handler....
r2506 rpt_add(sec_sep)
rpt_add('Application name: %s\n\n' % self.app_name)
rpt_add('Current user configuration structure:\n\n')
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 rpt_add(config)
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 except:
pass
Fernando Perez
Move crash handling to the application level and simplify class structure....
r2403 rpt_add(sec_sep+'Crash traceback:\n\n' + traceback)
fperez
Reorganized the directory for ipython/ to have its own dir, which is a bit...
r0
fptest
- Made the internal crash handler very customizable for end-user apps based...
r381 return ''.join(report)
MinRK
Don't use crash_handler by default...
r5317
def crash_handler_lite(etype, evalue, tb):
"""a light excepthook, adding a small message to the usual traceback"""
traceback.print_exception(etype, evalue, tb)
from IPython.core.interactiveshell import InteractiveShell
if InteractiveShell.initialized():
# we are in a Shell environment, give %magic example
config = "%config "
else:
# we are not in a shell, show generic config
config = "c."
Matthias Bussonnier
print the version on crash
r25284 print(_lite_message_template.format(email=author_email, config=config, version=version), file=sys.stderr)
MinRK
Don't use crash_handler by default...
r5317