def __init__(self, fn): ''' generate a CallTree with the given function ''' assert callable( fn), 'CallTree needs a function as its argument, not {}'.format(fn) sio = StringIO() p = Pdb(stdout=sio) for i in range(512): p.cmdqueue.append('s') p.cmdqueue.append('q') p.runcall(fn) sio.seek(0) self.target_fn = fn self.pdb_text = sio.read()