diff options
author | Kurt B. Kaiser <kbk@shore.net> | 2003-02-27 23:04:17 (GMT) |
---|---|---|
committer | Kurt B. Kaiser <kbk@shore.net> | 2003-02-27 23:04:17 (GMT) |
commit | 86bc464414bf2122dc569ec6eff94ee2197611a5 (patch) | |
tree | bfe93bfa6b4a736527cd324ec2dbb42ff8e66ebd /Lib | |
parent | 4213e27616d7c33af41769975ebaa8c8ed1b15a2 (diff) | |
download | cpython-86bc464414bf2122dc569ec6eff94ee2197611a5.zip cpython-86bc464414bf2122dc569ec6eff94ee2197611a5.tar.gz cpython-86bc464414bf2122dc569ec6eff94ee2197611a5.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/idlelib/rpc.py | 43 | ||||
-rw-r--r-- | Lib/idlelib/run.py | 46 |
2 files changed, 46 insertions, 43 deletions
diff --git a/Lib/idlelib/rpc.py b/Lib/idlelib/rpc.py index c79f4fe..54455a2 100644 --- a/Lib/idlelib/rpc.py +++ b/Lib/idlelib/rpc.py @@ -168,50 +168,9 @@ class SocketIO: raise 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, + traceback.print_exc(file=sys.__stderr__) 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): self.debug("remotecall:asynccall: ", oid, methodname) # XXX KBK 06Feb03 self.interrupted logic may not be necessary if diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 06fc049..e2594dd 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -1,6 +1,7 @@ import sys import time import socket +import traceback import boolcheck @@ -69,7 +70,50 @@ class Executive: self.calltip = CallTips.CallTips() def runcode(self, code): - exec code in self.locals + 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): # XXX KBK 05Feb03 Windows requires this be done with messages and |