Show More
@@ -1,111 +1,111 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """sys.excepthook for IPython itself, leaves a detailed report on disk. |
|
2 | """sys.excepthook for IPython itself, leaves a detailed report on disk. | |
3 |
|
3 | |||
4 |
$Id: CrashHandler.py |
|
4 | $Id: CrashHandler.py 1320 2006-05-23 18:29:11Z vivainio $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
|
7 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #***************************************************************************** |
|
11 | #***************************************************************************** | |
12 |
|
12 | |||
13 | from IPython import Release |
|
13 | from IPython import Release | |
14 | __author__ = '%s <%s>' % Release.authors['Fernando'] |
|
14 | __author__ = '%s <%s>' % Release.authors['Fernando'] | |
15 | __license__ = Release.license |
|
15 | __license__ = Release.license | |
16 | __version__ = Release.version |
|
16 | __version__ = Release.version | |
17 |
|
17 | |||
18 | #**************************************************************************** |
|
18 | #**************************************************************************** | |
19 | # Required modules |
|
19 | # Required modules | |
20 |
|
20 | |||
21 | # From the standard library |
|
21 | # From the standard library | |
22 | import os |
|
22 | import os | |
23 | import sys |
|
23 | import sys | |
24 | from pprint import pprint,pformat |
|
24 | from pprint import pprint,pformat | |
25 |
|
25 | |||
26 | # Homebrewed |
|
26 | # Homebrewed | |
27 | from IPython.Itpl import Itpl,itpl,printpl |
|
27 | from IPython.Itpl import Itpl,itpl,printpl | |
28 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names |
|
28 | from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names | |
29 | from IPython import ultraTB |
|
29 | from IPython import ultraTB | |
30 | from IPython.genutils import * |
|
30 | from IPython.genutils import * | |
31 |
|
31 | |||
32 | #**************************************************************************** |
|
32 | #**************************************************************************** | |
33 | class CrashHandler: |
|
33 | class CrashHandler: | |
34 | """sys.excepthook for IPython itself, leaves a detailed report on disk.""" |
|
34 | """sys.excepthook for IPython itself, leaves a detailed report on disk.""" | |
35 |
|
35 | |||
36 | def __init__(self,IP): |
|
36 | def __init__(self,IP): | |
37 | self.IP = IP # IPython instance |
|
37 | self.IP = IP # IPython instance | |
38 |
self.bug_contact = Release.authors[' |
|
38 | self.bug_contact = Release.authors['Ville'][0] | |
39 |
self.mailto = Release.authors[' |
|
39 | self.mailto = Release.authors['Ville'][1] | |
40 |
|
40 | |||
41 | def __call__(self,etype, evalue, etb): |
|
41 | def __call__(self,etype, evalue, etb): | |
42 |
|
42 | |||
43 | # Report tracebacks shouldn't use color in general (safer for users) |
|
43 | # Report tracebacks shouldn't use color in general (safer for users) | |
44 | color_scheme = 'NoColor' |
|
44 | color_scheme = 'NoColor' | |
45 |
|
45 | |||
46 | # Use this ONLY for developer debugging (keep commented out for release) |
|
46 | # Use this ONLY for developer debugging (keep commented out for release) | |
47 | #color_scheme = 'Linux' # dbg |
|
47 | #color_scheme = 'Linux' # dbg | |
48 |
|
48 | |||
49 | try: |
|
49 | try: | |
50 | rptdir = self.IP.rc.ipythondir |
|
50 | rptdir = self.IP.rc.ipythondir | |
51 | except: |
|
51 | except: | |
52 | rptdir = os.getcwd() |
|
52 | rptdir = os.getcwd() | |
53 | if not os.path.isdir(rptdir): |
|
53 | if not os.path.isdir(rptdir): | |
54 | rptdir = os.getcwd() |
|
54 | rptdir = os.getcwd() | |
55 | self.report_name = os.path.join(rptdir,'IPython_crash_report.txt') |
|
55 | self.report_name = os.path.join(rptdir,'IPython_crash_report.txt') | |
56 | self.TBhandler = ultraTB.VerboseTB(color_scheme=color_scheme,long_header=1) |
|
56 | self.TBhandler = ultraTB.VerboseTB(color_scheme=color_scheme,long_header=1) | |
57 | traceback = self.TBhandler.text(etype,evalue,etb,context=31) |
|
57 | traceback = self.TBhandler.text(etype,evalue,etb,context=31) | |
58 |
|
58 | |||
59 | # print traceback to screen |
|
59 | # print traceback to screen | |
60 | print >> sys.stderr, traceback |
|
60 | print >> sys.stderr, traceback | |
61 |
|
61 | |||
62 | # and generate a complete report on disk |
|
62 | # and generate a complete report on disk | |
63 | try: |
|
63 | try: | |
64 | report = open(self.report_name,'w') |
|
64 | report = open(self.report_name,'w') | |
65 | except: |
|
65 | except: | |
66 | print >> sys.stderr, 'Could not create crash report on disk.' |
|
66 | print >> sys.stderr, 'Could not create crash report on disk.' | |
67 | return |
|
67 | return | |
68 |
|
68 | |||
69 | msg = itpl('\n'+'*'*70+'\n' |
|
69 | msg = itpl('\n'+'*'*70+'\n' | |
70 | """ |
|
70 | """ | |
71 | Oops, IPython crashed. We do our best to make it stable, but... |
|
71 | Oops, IPython crashed. We do our best to make it stable, but... | |
72 |
|
72 | |||
73 | A crash report was automatically generated with the following information: |
|
73 | A crash report was automatically generated with the following information: | |
74 | - A verbatim copy of the traceback above this text. |
|
74 | - A verbatim copy of the traceback above this text. | |
75 | - A copy of your input history during this session. |
|
75 | - A copy of your input history during this session. | |
76 | - Data on your current IPython configuration. |
|
76 | - Data on your current IPython configuration. | |
77 |
|
77 | |||
78 | It was left in the file named: |
|
78 | It was left in the file named: | |
79 | \t'$self.report_name' |
|
79 | \t'$self.report_name' | |
80 | If you can email this file to the developers, the information in it will help |
|
80 | If you can email this file to the developers, the information in it will help | |
81 | them in understanding and correcting the problem. |
|
81 | them in understanding and correcting the problem. | |
82 |
|
82 | |||
83 | You can mail it to $self.bug_contact at $self.mailto |
|
83 | You can mail it to $self.bug_contact at $self.mailto | |
84 | with the subject 'IPython Crash Report'. |
|
84 | with the subject 'IPython Crash Report'. | |
85 |
|
85 | |||
86 | If you want to do it now, the following command will work (under Unix): |
|
86 | If you want to do it now, the following command will work (under Unix): | |
87 | mail -s 'IPython Crash Report' $self.mailto < $self.report_name |
|
87 | mail -s 'IPython Crash Report' $self.mailto < $self.report_name | |
88 |
|
88 | |||
89 | To ensure accurate tracking of this issue, please file a report about it at: |
|
89 | To ensure accurate tracking of this issue, please file a report about it at: | |
90 | http://www.scipy.net/roundup/ipython (IPython's online bug tracker). |
|
90 | http://www.scipy.net/roundup/ipython (IPython's online bug tracker). | |
91 | """) |
|
91 | """) | |
92 | print >> sys.stderr, msg |
|
92 | print >> sys.stderr, msg | |
93 |
|
93 | |||
94 | sec_sep = '\n\n'+'*'*75+'\n\n' |
|
94 | sec_sep = '\n\n'+'*'*75+'\n\n' | |
95 | report.write('*'*75+'\n\n'+'IPython post-mortem report\n\n') |
|
95 | report.write('*'*75+'\n\n'+'IPython post-mortem report\n\n') | |
96 | report.write('IPython version: %s \n\n' % Release.version) |
|
96 | report.write('IPython version: %s \n\n' % Release.version) | |
97 | report.write('SVN revision : %s \n\n' % Release.revision) |
|
97 | report.write('SVN revision : %s \n\n' % Release.revision) | |
98 | report.write('Platform info : os.name -> %s, sys.platform -> %s' % |
|
98 | report.write('Platform info : os.name -> %s, sys.platform -> %s' % | |
99 | (os.name,sys.platform) ) |
|
99 | (os.name,sys.platform) ) | |
100 | report.write(sec_sep+'Current user configuration structure:\n\n') |
|
100 | report.write(sec_sep+'Current user configuration structure:\n\n') | |
101 | report.write(pformat(self.IP.rc.dict())) |
|
101 | report.write(pformat(self.IP.rc.dict())) | |
102 | report.write(sec_sep+'Crash traceback:\n\n' + traceback) |
|
102 | report.write(sec_sep+'Crash traceback:\n\n' + traceback) | |
103 | try: |
|
103 | try: | |
104 | report.write(sec_sep+"History of session input:") |
|
104 | report.write(sec_sep+"History of session input:") | |
105 | for line in self.IP.user_ns['_ih']: |
|
105 | for line in self.IP.user_ns['_ih']: | |
106 | report.write(line) |
|
106 | report.write(line) | |
107 | report.write('\n*** Last line of input (may not be in above history):\n') |
|
107 | report.write('\n*** Last line of input (may not be in above history):\n') | |
108 | report.write(self.IP._last_input_line+'\n') |
|
108 | report.write(self.IP._last_input_line+'\n') | |
109 | except: |
|
109 | except: | |
110 | pass |
|
110 | pass | |
111 | report.close() |
|
111 | report.close() |
General Comments 0
You need to be logged in to leave comments.
Login now