def __init__(self): """ Initialize. Redirect I/O to console """ ConsoleView.__init__(self) self.cout = StringIO() IterableIPShell.__init__(self, cout=self.cout, cerr=self.cout, input_func=self.raw_input) displayhook = MyPromptDisplayHook(shell=self.IP, view=self) self.IP.displayhook = displayhook self.IP.display_trap = DisplayTrap(hook=displayhook) self.interrupt = False self.execute() self.prompt = self.generatePrompt(False) self.cout.truncate(0) self.showPrompt(self.prompt)
def debugger(self,force=False): """Call up the pdb debugger if desired, always clean up the tb reference. Keywords: - force(False): by default, this routine checks the instance call_pdb flag and does not actually invoke the debugger if the flag is false. The 'force' option forces the debugger to activate even if the flag is false. If the call_pdb flag is set, the pdb interactive debugger is invoked. In all cases, the self.tb reference to the current traceback is deleted to prevent lingering references which hamper memory management. Note that each call to pdb() does an 'import readline', so if your app requires a special setup for the readline completers, you'll have to fix that by hand after invoking the exception handler.""" if force or self.call_pdb: if self.pdb is None: self.pdb = debugger.Pdb( self.color_scheme_table.active_scheme_name) # the system displayhook may have changed, restore the original # for pdb display_trap = DisplayTrap(hook=sys.__displayhook__) with display_trap: self.pdb.reset() # Find the right frame so we don't pop up inside ipython itself if hasattr(self,'tb') and self.tb is not None: etb = self.tb else: etb = self.tb = sys.last_traceback while self.tb is not None and self.tb.tb_next is not None: self.tb = self.tb.tb_next if etb and etb.tb_next: etb = etb.tb_next self.pdb.botframe = etb.tb_frame self.pdb.interaction(self.tb.tb_frame, self.tb) if hasattr(self,'tb'): del self.tb