You could consider subclassing the python debugger. Have a look at lib/bdb.py and lib/pdb.py. You get pretty fine grained control over the interpreter this way.