##// END OF EJS Templates
Restore sys.last_traceback and friends, for the benefit of pdb.pm(). Let's hope it doesn't cause problems with threaded shells (tested, OK so far). Other exception-related cleanups.
fperez -
Show More
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 1140 2006-02-10 17:07:11Z vivainio $
9 $Id: iplib.py 1202 2006-03-12 06:37:52Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -1282,6 +1282,12 b' want to merge them back into the new files.""" % locals()'
1282 "<string>" when reading from a string).
1282 "<string>" when reading from a string).
1283 """
1283 """
1284 etype, value, last_traceback = sys.exc_info()
1284 etype, value, last_traceback = sys.exc_info()
1285
1286 # See note about these variables in showtraceback() below
1287 sys.last_type = etype
1288 sys.last_value = value
1289 sys.last_traceback = last_traceback
1290
1285 if filename and etype is SyntaxError:
1291 if filename and etype is SyntaxError:
1286 # Work hard to stuff the correct filename in the exception
1292 # Work hard to stuff the correct filename in the exception
1287 try:
1293 try:
@@ -1306,19 +1312,27 b' want to merge them back into the new files.""" % locals()'
1306 return
1312 return
1307 pdb.pm()
1313 pdb.pm()
1308
1314
1309 def showtraceback(self,exc_tuple = None,filename=None):
1315 def showtraceback(self,exc_tuple = None,filename=None,tb_offset=None):
1310 """Display the exception that just occurred."""
1316 """Display the exception that just occurred."""
1311
1317
1312 # Though this won't be called by syntax errors in the input line,
1318 # Though this won't be called by syntax errors in the input line,
1313 # there may be SyntaxError cases whith imported code.
1319 # there may be SyntaxError cases whith imported code.
1314 if exc_tuple is None:
1320 if exc_tuple is None:
1315 type, value, tb = sys.exc_info()
1321 etype, value, tb = sys.exc_info()
1316 else:
1322 else:
1317 type, value, tb = exc_tuple
1323 etype, value, tb = exc_tuple
1318 if type is SyntaxError:
1324 if etype is SyntaxError:
1319 self.showsyntaxerror(filename)
1325 self.showsyntaxerror(filename)
1320 else:
1326 else:
1321 self.InteractiveTB()
1327 # WARNING: these variables are somewhat deprecated and not
1328 # necessarily safe to use in a threaded environment, but tools
1329 # like pdb depend on their existence, so let's set them. If we
1330 # find problems in the field, we'll need to revisit their use.
1331 sys.last_type = etype
1332 sys.last_value = value
1333 sys.last_traceback = tb
1334
1335 self.InteractiveTB(etype,value,tb,tb_offset=tb_offset)
1322 if self.InteractiveTB.call_pdb and self.has_readline:
1336 if self.InteractiveTB.call_pdb and self.has_readline:
1323 # pdb mucks up readline, fix it back
1337 # pdb mucks up readline, fix it back
1324 self.readline.set_completer(self.Completer.complete)
1338 self.readline.set_completer(self.Completer.complete)
@@ -1489,7 +1503,7 b' want to merge them back into the new files.""" % locals()'
1489 # We are off again...
1503 # We are off again...
1490 __builtin__.__dict__['__IPYTHON__active'] -= 1
1504 __builtin__.__dict__['__IPYTHON__active'] -= 1
1491
1505
1492 def excepthook(self, type, value, tb):
1506 def excepthook(self, etype, value, tb):
1493 """One more defense for GUI apps that call sys.excepthook.
1507 """One more defense for GUI apps that call sys.excepthook.
1494
1508
1495 GUI frameworks like wxPython trap exceptions and call
1509 GUI frameworks like wxPython trap exceptions and call
@@ -1511,10 +1525,7 b' want to merge them back into the new files.""" % locals()'
1511 This hook should be used sparingly, only in places which are not likely
1525 This hook should be used sparingly, only in places which are not likely
1512 to be true IPython errors.
1526 to be true IPython errors.
1513 """
1527 """
1514
1528 self.showtraceback((etype,value,tb),tb_offset=0)
1515 self.InteractiveTB(type, value, tb, tb_offset=0)
1516 if self.InteractiveTB.call_pdb and self.has_readline:
1517 self.readline.set_completer(self.Completer.complete)
1518
1529
1519 def transform_alias(self, alias,rest=''):
1530 def transform_alias(self, alias,rest=''):
1520 """ Transform alias to system command string
1531 """ Transform alias to system command string
@@ -2254,15 +2265,14 b' want to merge them back into the new files.""" % locals()'
2254 try:
2265 try:
2255 execfile(fname,*where)
2266 execfile(fname,*where)
2256 except SyntaxError:
2267 except SyntaxError:
2257 etype,evalue = sys.exc_info()[:2]
2268 self.showsyntaxerror()
2258 self.SyntaxTB(etype,evalue,[])
2259 warn('Failure executing file: <%s>' % fname)
2269 warn('Failure executing file: <%s>' % fname)
2260 except SystemExit,status:
2270 except SystemExit,status:
2261 if not kw['exit_ignore']:
2271 if not kw['exit_ignore']:
2262 self.InteractiveTB()
2272 self.showtraceback()
2263 warn('Failure executing file: <%s>' % fname)
2273 warn('Failure executing file: <%s>' % fname)
2264 except:
2274 except:
2265 self.InteractiveTB()
2275 self.showtraceback()
2266 warn('Failure executing file: <%s>' % fname)
2276 warn('Failure executing file: <%s>' % fname)
2267
2277
2268 #************************* end of file <iplib.py> *****************************
2278 #************************* end of file <iplib.py> *****************************
@@ -1,3 +1,17 b''
1 2006-03-11 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (showtraceback): add back sys.last_traceback
4 and friends, after a discussion with Zach Pincus on ipython-user.
5 I'm not 100% sure, but after thinking aobut it quite a bit, it may
6 be OK. Testing with the multithreaded shells didn't reveal any
7 problems, but let's keep an eye out.
8
9 In the process, I fixed a few things which were calling
10 self.InteractiveTB() directly (like safe_execfile), which is a
11 mistake: ALL exception reporting should be done by calling
12 self.showtraceback(), which handles state and tab-completion and
13 more.
14
1 2006-03-01 Ville Vainio <vivainio@gmail.com>
15 2006-03-01 Ville Vainio <vivainio@gmail.com>
2
16
3 * Extensions/ipipe.py: Added Walter Doerwald's "ipipe" module.
17 * Extensions/ipipe.py: Added Walter Doerwald's "ipipe" module.
General Comments 0
You need to be logged in to leave comments. Login now