Dabo in 30 seconds?

Fernando Perez fperez.net at gmail.com
Tue Aug 2 13:40:37 EDT 2005


Ed Leafe wrote:

> On Monday 01 August 2005 11:56, Terry Reedy wrote:
> 
>> That is an impossibility.  However, there is a middle path between that and
>> no defensive code.  In the present case, you appear to acknowledge a known
>> easy way to mis-compile wxWidgets from Dabo's viewpoint.  If there is a
>> known easy way to detect that misconfiguration (which I suspect there is),
>> and it is known that someone has tripped over that problem (which it now
>> is), then a nice error message  like 'Sorry, Dabo need wxWidgets compiled
>> with the --include_stylized_text option' would certainly be friendlier than
>> a stack trace.
> 
>  OK, that's more of what I had in mind. Truth be told, this is the first time
> we've run into this, and as a result I'll make the change to that import
> statement today.

<plug, but hopefully a useful one>

You may want to steal the crash handling code from ipython.  In order to
address this kind of problem, ipython sticks an exceptionally verbose
traceback printer into sys.excepthook.  If ipython ever crashes, the user gets
a LOT of info, and it's all packaged ready to go, to be emailed to me.  Here's
an example of the result (I stuck 1/0 inside to force the crash):

In [1]: print 'hello'
hello

In [2]:
---------------------------------------------------------------------------
exceptions.ZeroDivisionError                             Python
2.3.4: /usr/bin/python
                                                   Tue Aug  2 11:21:46 2005
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.

/home/fperez/usr/bin/ipython
     -2 import IPython
     -1
      0 IPython.Shell.start().mainloop()

/usr/local/home/fperez/code/python/IPython/Shell.py in
mainloop(self=<IPython.Shell.IPShell instance>, sys_exit=0, banner=None)

/home/fperez/code/python/IPython/iplib.py in
mainloop(self=<IPython.iplib.InteractiveShell instance>, banner='Python 2.3.4
(#1, Feb  2 2005, 12:11:53) \nType "...ut \'object\'. ?object also works, ??
prints more.\n')
   1263
   1264     def mainloop(self,banner=None):
   1265         """Creates the local namespace and starts the mainloop.
   1266
   1267         If an optional banner argument is given, it will override the
   1268         internally created default banner."""
   1269
   1270         self.name_space_init()
   1271         if self.rc.c:  # Emulate Python's -c option
   1272             self.exec_init_cmd()
   1273         if banner is None:
   1274             if self.rc.banner:
   1275                 banner = self.BANNER+self.banner2
   1276             else:
   1277                 banner = ''
-> 1278         self.interact(banner)
        self.interact = <bound method InteractiveShell.interact of
<IPython.iplib.InteractiveShell instance at 0x4005ffac>>
        banner = 'Python 2.3.4 (#1, Feb  2 2005, 12:11:53) \nType "copyright",
"credits" or "license" for more information.\n\nIPython 0.6.16_svn -- An
enhanced Interactive Python.\n?       -> Introduction to IPython\'s features
\n%magic  -> Information about IPython\'s \'magic\' % functions.\nhelp    ->
Python\'s own help system.\nobject? -> Details about \'object\'. ?object also
works, ?? prints more.\n'
   1279
   1280     def exec_init_cmd(self):
   1281         """Execute a command given at the command line.
   1282
   1283         This emulates Python's -c option."""
   1284
   1285         sys.argv = ['-c']
   1286         self.push(self.rc.c)
   1287
   1288     def
embed_mainloop(self,header='',local_ns=None,global_ns=None,stack_depth=0):
   1289         """Embeds IPython into a running python program.
   1290
   1291         Input:
   1292
   1293           - header: An optional header message can be specified.


[...]

LOTS MORE: each stack frame has a lot of surrounding context printed, and all
locals as well.

Then this is the end of the printout:

   1399             except KeyboardInterrupt:
-> 1400                 1/0

   1401                 self.write("\nKeyboardInterrupt\n")
   1402                 self.resetbuffer()
   1403                 more = 0
   1404                 # keep cache in sync with the prompt counter:
   1405                 self.outputcache.prompt_count -= 1
   1406
   1407                 if self.autoindent:
   1408                     self.readline_indent = 0
   1409
   1410             except bdb.BdbQuit:
   1411                 warn("The Python debugger has exited with a BdbQuit
exception.\n"
   1412                      "Because of how pdb handles the stack, it is
impossible\n"
   1413                      "for IPython to properly format this particular
exception.\n"
   1414                      "IPython will resume normal operation.")
   1415

ZeroDivisionError: integer division or modulo by zero

**********************************************************************

Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the traceback above this text.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It was left in the file named:
        '/home/fperez/.ipython/IPython_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to Fernando Perez at fperez at colorado.edu
with the subject 'IPython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' fperez at colorado.edu
< /home/fperez/.ipython/IPython_crash_report.txt

To ensure accurate tracking of this issue, please file a report about it at:
http://www.scipy.net/roundup/ipython  (IPython's online bug tracker).


[END IPYTHON CRASH PRINTOUT]

The point is that something like this:

- gives an experienced user a lot of information to track down the bug if they
feel like it.

- but also gives the raw newbie an easy solution: just mail me that
auto-generated crash file and forget about it.

In fact, I've received over the years many tracebacks with enough detail for me
to fix a problem in ipython (or to code defensively against broken third-party
libs or bugs in the stdlib).  And many of these problems could only be
reproduced with user data I had no access to, but the traceback has enough
detail that I can often understand the problem and fix it just based on that.

This approach has worked very well for me over the years, and these crash
report emails have become fortunately rather rare as of late :)

If you are interested, just get ipython and grab the files for this, it's all
BSD licensed.  You can also browse the SVN repo here if you want to look at
the code:

http://ipython.scipy.org/svn/ipython/ipython/trunk/IPython/

The relevant files are ultraTB.py and CrashHandler.py.

Cheers,

f




More information about the Python-list mailing list