display instance variables one level deep

This commit is contained in:
Darren Ranalli 2008-09-04 00:44:26 +00:00
parent b48a493323
commit 37c9bcdb56
2 changed files with 19 additions and 5 deletions

View File

@ -60,19 +60,23 @@ def _varDump__print(exc):
sReentry -= 1
oldExcepthook = None
# store these values here so that Task.py can always reliably access these values
# store these values here so that Task.py can always reliably access them
# from its main exception handler
wantVariableDump = False
dumpOnExceptionInit = False
def _excepthookDumpVars(eType, eValue, traceback):
class _AttrNotFound:
pass
def _excepthookDumpVars(eType, eValue, tb):
s = 'DUMPING STACK FRAME VARIABLES'
tb = traceback
origTb = tb
#import pdb;pdb.set_trace()
foundRun = False
while tb is not None:
frame = tb.tb_frame
code = frame.f_code
names = code.co_names
tb = tb.tb_next
# skip everything before the 'run' method, those frames have lots of
# not-useful information
@ -84,13 +88,22 @@ def _excepthookDumpVars(eType, eValue, traceback):
s += '\n File "%s", line %s, in %s' % (
code.co_filename, frame.f_lineno, code.co_name)
for name, val in frame.f_locals.iteritems():
r = fastRepr(val)
r = fastRepr(val, maxLen=10)
if type(r) is types.StringType:
r = r.replace('\n', '\\n')
s += '\n %s=%s' % (name, r)
# check if we should display any immediate attributes of the object
for n in names:
a = getattr(val, n, _AttrNotFound)
if a is not _AttrNotFound:
r = fastRepr(a, maxLen=10)
if type(r) is types.StringType:
r = r.replace('\n', '\\n')
s += '\n %s.%s=%s' % (name, n, r)
s += '\n'
notify.info(s)
oldExcepthook(eType, eValue, traceback)
oldExcepthook(eType, eValue, origTb)
def install():
global oldExcepthook

View File

@ -2321,6 +2321,7 @@ def fastRepr(obj, maxLen=200, strFactor=10, _visitedIds=None):
return safeRepr(obj)
else:
r = safeRepr(obj)
maxLen *= strFactor
if len(r) > maxLen:
r = r[:maxLen]
return r