[Idle-dev] CVS: idle rpc.py,1.16,1.17 run.py,1.10,1.11
Kurt B. Kaiser
kbk@users.sourceforge.net
Thu, 27 Feb 2003 15:04:23 -0800
Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv2438
Modified Files:
rpc.py run.py
Log Message:
M rpc.py
M run.py
Move exception formatting out of rpc.py. This allows each end of the
link to format and print exceptions how and where it sees fit and makes it
easier for threads to display their own exceptions.
Index: rpc.py
===================================================================
RCS file: /cvsroot/idlefork/idle/rpc.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -r1.16 -r1.17
*** rpc.py 17 Feb 2003 18:57:16 -0000 1.16
--- rpc.py 27 Feb 2003 23:04:15 -0000 1.17
***************
*** 169,215 ****
except:
self.debug("localcall:EXCEPTION")
! if self.debugging: traceback.print_exc(file=sys.__stderr__)
! efile = sys.stderr
! typ, val, tb = info = sys.exc_info()
! sys.last_type, sys.last_value, sys.last_traceback = info
! tbe = traceback.extract_tb(tb)
! print >>efile, '\nTraceback (most recent call last):'
! exclude = ("run.py", "rpc.py", "RemoteDebugger.py", "bdb.py")
! self.cleanup_traceback(tbe, exclude)
! traceback.print_list(tbe, file=efile)
! lines = traceback.format_exception_only(typ, val)
! for line in lines:
! print>>efile, line,
return ("EXCEPTION", None)
-
- def cleanup_traceback(self, tb, exclude):
- "Remove excluded traces from beginning/end of tb; get cached lines"
- orig_tb = tb[:]
- while tb:
- for rpcfile in exclude:
- if tb[0][0].count(rpcfile):
- break # found an exclude, break for: and delete tb[0]
- else:
- break # no excludes, have left RPC code, break while:
- del tb[0]
- while tb:
- for rpcfile in exclude:
- if tb[-1][0].count(rpcfile):
- break
- else:
- break
- del tb[-1]
- if len(tb) == 0:
- # exception was in RPC internals, don't prune!
- tb[:] = orig_tb[:]
- print>>sys.stderr, "** IDLE RPC Internal Exception: "
- for i in range(len(tb)):
- fn, ln, nm, line = tb[i]
- if nm == '?':
- nm = "-toplevel-"
- if not line and fn.startswith("<pyshell#"):
- line = self.remotecall('linecache', 'getline',
- (fn, ln), {})
- tb[i] = fn, ln, nm, line
def remotecall(self, oid, methodname, args, kwargs):
--- 169,174 ----
except:
self.debug("localcall:EXCEPTION")
! traceback.print_exc(file=sys.__stderr__)
return ("EXCEPTION", None)
def remotecall(self, oid, methodname, args, kwargs):
Index: run.py
===================================================================
RCS file: /cvsroot/idlefork/idle/run.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** run.py 17 Feb 2003 18:57:16 -0000 1.10
--- run.py 27 Feb 2003 23:04:17 -0000 1.11
***************
*** 2,5 ****
--- 2,6 ----
import time
import socket
+ import traceback
import boolcheck
***************
*** 70,74 ****
def runcode(self, code):
! exec code in self.locals
def interrupt_the_server(self):
--- 71,118 ----
def runcode(self, code):
! try:
! exec code in self.locals
! except:
! efile = sys.stderr
! typ, val, tb = info = sys.exc_info()
! sys.last_type, sys.last_value, sys.last_traceback = info
! tbe = traceback.extract_tb(tb)
! print >>efile, '\nTraceback (most recent call last):'
! exclude = ("run.py", "rpc.py", "RemoteDebugger.py", "bdb.py")
! self.cleanup_traceback(tbe, exclude)
! traceback.print_list(tbe, file=efile)
! lines = traceback.format_exception_only(typ, val)
! for line in lines:
! print>>efile, line,
!
! def cleanup_traceback(self, tb, exclude):
! "Remove excluded traces from beginning/end of tb; get cached lines"
! orig_tb = tb[:]
! while tb:
! for rpcfile in exclude:
! if tb[0][0].count(rpcfile):
! break # found an exclude, break for: and delete tb[0]
! else:
! break # no excludes, have left RPC code, break while:
! del tb[0]
! while tb:
! for rpcfile in exclude:
! if tb[-1][0].count(rpcfile):
! break
! else:
! break
! del tb[-1]
! if len(tb) == 0:
! # exception was in IDLE internals, don't prune!
! tb[:] = orig_tb[:]
! print>>sys.stderr, "** IDLE Internal Exception: "
! for i in range(len(tb)):
! fn, ln, nm, line = tb[i]
! if nm == '?':
! nm = "-toplevel-"
! if not line and fn.startswith("<pyshell#"):
! line = self.rpchandler.remotecall('linecache', 'getline',
! (fn, ln), {})
! tb[i] = fn, ln, nm, line
def interrupt_the_server(self):