Sometimes its hard to see whats going on during the debug process, then the traceback module can help you out. It would be useful if you could monitor individual function calls too. Here i demonstrate how a simple function can be used to wrap around a function and give some meaningful feedback on what function call was issued and what it was issued with.
The downside is that this can slow down the process immensely and produce a lot of data so a easy way to switch it off is needed
A quick sample follows:
from vcScript import *
# make a simple global switch for easy switching
DEBUG=True
def doDebug(fn):
import traceback
def new(*args):
try:
a=traceback.extract_stack()
print a[0][0]+" line "+repr(a[0][1])+ ": "+ fn.__name__+repr(args)+" returns "+repr(fn(*args))
return fn(*args)
except:
pass
#if debug is on lets wrap the function else leave it be
if DEBUG:
return new
else:
return fn
# demontsration
def dummy(aa,bb):
return aa+bb+1
# now redefine it to get the wrap around
dummy=doDebug(dummy)
#even our api commands can be surrounded
getComponent=doDebug(getComponent)
# and finally some test that runs
# when you compile to demo the effect
getComponent()
dummy(10,2)