[IPython-user] Re: IPython Crash Report
Gary Bishop
gb at cs.unc.edu
Tue May 13 14:11:30 CDT 2003
Hi Fernando,
I've got a simple modification to IPython that handles my example. It
may well break something else, I have only begun to appreciate the
subtleties of your code.
The idea is simple. I assume that during the exec in
InteractiveShell.runcode, calls to sys.excepthook are just another
normal exception rather than a crash in IPython. I do this by swapping
in a local excepthook just before the exec and swapping it back out
just after. I added 3 methods to InteractiveShell: excepthook (the
local handler), setexcepthook (to swap it in) and clearexcepthook (to
swap it out).
I also modified AutoFormattedTB to 1) respect etype,value, and tb args
if they are given, and 2) to accept an offset argument to temporarily
override the tb_offset. There is probably a better way to accomplish this...
Here are the diffs and I will attach the new files. I probably have
missed some important case so I'd like to hear your feedback on this
approach. I *really* like IPython and would like to make it work for wxPython.
Thanks
gb
$ diff iplib.py~ iplib.py
781a782,807
> def excepthook(self, type, value, tb):
> '''One more defense for GUI apps that call sys.excepthook.
> GUI frameworks like wxPython trap exceptions and call
> sys.excepthook themselves. I guess this is a feature that
> enables them to keep running after exceptions that would
> otherwise kill their mainloop. This is a bother for IPython
> which excepts to catch all of the program exceptions with a try:
> except: statement. IPython ends up thinking it has crashed. I
> swap in this excepthook just before the exec in runcode below,
> so that we can treat calls to sys.excepthook as a normal thing
> in this special case.
> '''
> self.InteractiveTB(type, value, tb, offset=0)
> if self.InteractiveTB.call_pdb and self.has_readline:
> self.readline.set_completer(self.Completer.complete)
> def setexcepthook(self):
> '''establish our hook in place of the standard only during a command.'''
> self.old_excepthook = sys.excepthook
> sys.excepthook = self.excepthook
> def clearexcepthook(self):
> '''clear our hook and restore the old "last line of defense"'
> sys.excepthook = self.old_excepthook
788a815
> self.setexcepthook()
789a817
> self.clearexcepthook()
791a820
> self.clearexcepthook()
801a831
> self.clearexcepthook()
$ diff ultraTB.py~ ultraTB.py
686c686
< def __call__(self, etype=None, evalue=None, etb=None,out=None):
---
> def __call__(self, etype=None, evalue=None, etb=None,out=None,offset=None):
689c689,694
< print >> out, self.text()
---
> if offset is not None:
> offset, self.tb_offset = self.tb_offset, offset
> print >> out, self.text(etype, evalue, etb)
> self.tb_offset = offset
> else:
> print >> out, self.text()
693c698,699
< etype,value,tb = sys.exc_info()
---
> if etype is None:
> etype,value,tb = sys.exc_info()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-python
Size: 46710 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/ipython-user/attachments/20030513/60d66816/attachment.py
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-python
Size: 30975 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/ipython-user/attachments/20030513/60d66816/attachment-0001.py
More information about the IPython-user
mailing list