ipython/ipython — Issue #1298: Save ipython debugging session history (>= 0.11)
Author: rc
Created: 2012-01-20 09:58:54+00:00
State: open

When using code below as a pdb replacement (calling debug() instead of pdb.set_trace()), the commands entered during the debugging session are not saved into history. The "< 0.11" branch works ok.

old_excepthook = sys.excepthook

if IPython.__version__ >= '0.11':
from IPython.core.debugger import Pdb

try:
ip = get_ipython()

except NameError:
from IPython.frontend.terminal.embed \
import InteractiveShellEmbed
ip = InteractiveShellEmbed()

colors = ip.colors

else:
from IPython.Debugger import Pdb
from IPython.Shell import IPShell
from IPython import ipapi

ip = ipapi.get()
if ip is None:
IPShell(argv=[''])
ip = ipapi.get()

colors = ip.options.colors

def debug(frame=None):
sys.excepthook = old_excepthook

if frame is None:
frame = sys._getframe().f_back

Pdb(colors).set_trace(frame)