##// END OF EJS Templates
Only draw remote tracebacks for IPython.parallel remote exceptions
MinRK -
Show More
@@ -84,6 +84,11 b' from IPython.utils.traitlets import (Integer, CBool, CaselessStrEnum, Enum,'
84 from IPython.utils.warn import warn, error
84 from IPython.utils.warn import warn, error
85 import IPython.core.hooks
85 import IPython.core.hooks
86
86
87 try:
88 from IPython.parallel.error import RemoteError
89 except ImportError:
90 class RemoteError(Exception): pass
91
87 #-----------------------------------------------------------------------------
92 #-----------------------------------------------------------------------------
88 # Globals
93 # Globals
89 #-----------------------------------------------------------------------------
94 #-----------------------------------------------------------------------------
@@ -1711,6 +1716,10 b' class InteractiveShell(SingletonConfigurable):'
1711 self.showsyntaxerror(filename)
1716 self.showsyntaxerror(filename)
1712 elif etype is UsageError:
1717 elif etype is UsageError:
1713 self.write_err("UsageError: %s" % value)
1718 self.write_err("UsageError: %s" % value)
1719 elif issubclass(etype, RemoteError):
1720 # IPython.parallel remote exceptions.
1721 # Draw the remote traceback, not the local one.
1722 self._showtraceback(etype, value, value.render_traceback())
1714 else:
1723 else:
1715 if exception_only:
1724 if exception_only:
1716 stb = ['An exception has occurred, use %tb to see '
1725 stb = ['An exception has occurred, use %tb to see '
@@ -188,11 +188,17 b' class RemoteError(KernelError):'
188 return "<Remote[%s]:%s(%s)>"%(engineid, self.ename, self.evalue)
188 return "<Remote[%s]:%s(%s)>"%(engineid, self.ename, self.evalue)
189
189
190 def __str__(self):
190 def __str__(self):
191 sig = "%s(%s)"%(self.ename, self.evalue)
191 return "%s(%s)" % (self.ename, self.evalue)
192 if self.traceback:
192
193 return sig + '\n' + self.traceback
193 def render_traceback(self):
194 else:
194 """render traceback to a list of lines"""
195 return sig
195 return (self.traceback or "No traceback available").splitlines()
196
197 def print_traceback(self, excid=None):
198 """print my traceback"""
199 print('\n'.join(self.render_traceback()))
200
201
196
202
197
203
198 class TaskRejectError(KernelError):
204 class TaskRejectError(KernelError):
@@ -244,20 +250,27 b' class CompositeError(RemoteError):'
244 def __repr__(self):
250 def __repr__(self):
245 return "CompositeError(%i)"%len(self.elist)
251 return "CompositeError(%i)"%len(self.elist)
246
252
247 def print_tracebacks(self, excid=None):
253 def render_traceback(self, excid=None):
254 """render one or all of my tracebacks to a list of lines"""
255 lines = []
248 if excid is None:
256 if excid is None:
249 for (en,ev,etb,ei) in self.elist:
257 for (en,ev,etb,ei) in self.elist:
250 print (self._get_engine_str(ei))
258 lines.append(self._get_engine_str(ei))
251 print (etb or 'No traceback available')
259 lines.extend((etb or 'No traceback available').splitlines())
252 print ()
260 lines.append('')
253 else:
261 else:
254 try:
262 try:
255 en,ev,etb,ei = self.elist[excid]
263 en,ev,etb,ei = self.elist[excid]
256 except:
264 except:
257 raise IndexError("an exception with index %i does not exist"%excid)
265 raise IndexError("an exception with index %i does not exist"%excid)
258 else:
266 else:
259 print (self._get_engine_str(ei))
267 lines.append(self._get_engine_str(ei))
260 print (etb or 'No traceback available')
268 lines.extend((etb or 'No traceback available').splitlines())
269
270 return lines
271
272 def print_traceback(self, excid=None):
273 print('\n'.join(self.render_traceback(excid)))
261
274
262 def raise_exception(self, excid=0):
275 def raise_exception(self, excid=0):
263 try:
276 try:
General Comments 0
You need to be logged in to leave comments. Login now