import traceback
import types
import warnings
+import exceptions
import linecache
from code import InteractiveInterpreter
if clt is None:
return
response = clt.pollresponse(self.active_seq)
+ # Reschedule myself in 50 ms
self.tkconsole.text.after(50, self.poll_subprocess)
if response:
self.tkconsole.resetoutput()
line = linecache.getline(fn, ln)
tb[i] = fn, ln, nm, line
traceback.print_list(tb, file=file)
- if mod and mod != "exceptions":
- name = mod + "." + name
- print >>file, name + ":", " ".join(map(str, args))
+ # try to reinstantiate the exception, stuff in the args:
+ try:
+ etype = eval(mod + '.' + name)
+ val = etype()
+ val.args = args
+ except TypeError: # string exception!
+ etype = name
+ val = args
+ lines = traceback.format_exception_only(etype, val)
+ for line in lines[:-1]:
+ traceback._print(file, line, '')
+ traceback._print(file, lines[-1], '')
if self.tkconsole.getvar("<<toggle-jit-stack-viewer>>"):
self.remote_stack_viewer()
elif how == "ERROR":
- print >>sys.__stderr__, "Oops:", how, what
- print >>file, "Oops:", how, what
+ errmsg = "PyShell.ModifiedInterpreter: Subprocess ERROR:\n"
+ print >>sys.__stderr__, errmsg, what
+ print >>file, errmsg, what
self.tkconsole.endexecuting()
def kill_subprocess(self):
code = compile(source, filename, "exec")
except (OverflowError, SyntaxError):
self.tkconsole.resetoutput()
+ console = self.tkconsole.console
+ print >>console, 'Traceback (most recent call last):'
InteractiveInterpreter.showsyntaxerror(self, filename)
self.tkconsole.showprompt()
else:
class SocketIO:
- debugging = False
-
def __init__(self, sock, objtable=None, debugging=None):
self.mainthread = threading.currentThread()
if debugging is not None:
def debug(self, *args):
if not self.debugging:
return
- s = str(threading.currentThread().getName())
+ s = self.location + " " + str(threading.currentThread().getName())
for a in args:
s = s + " " + str(a)
- s = s + "\n"
- sys.__stderr__.write(s)
+ print>>sys.__stderr__, s
def register(self, oid, object):
self.objtable[oid] = object
typ, val, tb = info = sys.exc_info()
sys.last_type, sys.last_value, sys.last_traceback = info
if isinstance(typ, type(Exception)):
- # Class exceptions
+ # Class exception
mod = typ.__module__
name = typ.__name__
if issubclass(typ, Exception):
else:
args = (str(val),)
else:
- # String exceptions
+ # User string exception
mod = None
name = typ
- args = (str(val),)
+ if val is None: val = ''
+ args = str(val)
tb = traceback.extract_tb(tb)
+ self.debug("localcall:EXCEPTION: ", mod, name, args, tb)
return ("EXCEPTION", (mod, name, args, tb))
def remotecall(self, oid, methodname, args, kwargs):
- self.debug("remotecall:", oid, methodname, args, kwargs)
+ self.debug("remotecall:")
seq = self.asynccall(oid, methodname, args, kwargs)
- ret = self.asyncreturn(seq)
- self.debug("return:", ret)
- return ret
+ return self.asyncreturn(seq)
def asynccall(self, oid, methodname, args, kwargs):
- self.debug("asyncall:", oid, methodname, args, kwargs)
request = ("call", (oid, methodname, args, kwargs))
seq = self.putrequest(request)
+ self.debug(("asyncall:%d:" % seq), oid, methodname, args, kwargs)
return seq
def asyncreturn(self, seq):
response = self.getresponse(seq)
- self.debug("asyncreturn:", response)
+ self.debug(("asyncreturn:%d:" % seq), response)
return self.decoderesponse(response)
def decoderesponse(self, response):
if how == "OK":
return what
if how == "EXCEPTION":
+ self.debug("decoderesponse: Internal EXCEPTION:", what)
mod, name, args, tb = what
self.traceback = tb
if mod: # not string exception
# do the best we can:
raise name, args
if how == "ERROR":
+ self.debug("decoderesponse: Internal ERROR:", what)
raise RuntimeError, what
raise SystemError, (how, what)
return seq
def putmessage(self, message):
+ ##self.debug("putmessage: ", message)
try:
s = pickle.dumps(message)
except:
wait = 0.0
seq, resq = message
if resq[0] == "call":
+ self.debug("call_localcall:%d:" % seq)
response = self.localcall(resq)
self.putmessage((seq, response))
continue
class RPCHandler(SocketServer.BaseRequestHandler, SocketIO):
- debugging = 0
+ debugging = False
+ location = "#S" # Server
def __init__(self, sock, addr, svr):
svr.current_handler = self ## cgt xxx
class RPCClient(SocketIO):
+ debugging = False
+ location = "#C" # Client
+
nextseq = 1 # Requests coming from the client are odd numbered
def __init__(self, address, family=socket.AF_INET, type=socket.SOCK_STREAM):