Repository navigation
Description
Hi,
It does not appear to be currently possible to use the IPython debugger in conjunction with the simple-prompt mode and ipdb (from pypi : pip install ipdb).
This makes debugging multithreaded applications with ipdb and Emacs impossible (since the only way to break in the right thread is to put the snippet: import ipdb; ipdb.set_trace() in the code.
If I remove the "--simple-prompt" option then I get garbled text such as "^[[6n^[[Jipdb> ^[[6D^[[6C" at the ipdb prompt in Emacs since this is a dumb terminal which doesn't understand the special character escapes sent back by prompt_toolkit.
The traceback returned when using "--simple-prompt" is :
[...]
File "some_file.py", line 30, in some_function
import ipdb; ipdb.set_trace()
File "/home/maxim/.virtualenvs/project1/local/lib/python2.7/site-packages/ipdb/__main__.py", line 97, in set_trace
p = _init_pdb(context).set_trace(frame)
File "/home/maxim/.virtualenvs/project1/local/lib/python2.7/site-packages/ipdb/__main__.py", line 77, in _init_pdb
p = debugger_cls(def_colors, context=context)
File "/home/maxim/.virtualenvs/project1/local/lib/python2.7/site-packages/IPython/terminal/debugger.py", line 26, in __init__
self.pt_init()
File "/home/maxim/.virtualenvs/project1/local/lib/python2.7/site-packages/IPython/terminal/debugger.py", line 68, in pt_init
self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
AttributeError: 'TerminalInteractiveShell' object has no attribute '_eventloop'
It should be trivial to reproduce. Make sure you have ipdb installed (pip install ipdb).
- Create a script such as the following to a file named "ipdb_eventloop_repro.py":
print 'hello'
print ''
import ipdb; ipdb.set_trace()
print 'world'
- In a terminal, start the IPython process in 'simple-prompt' mode like this:
ipython --simple-prompt -c "%run -d ipdb_eventloop_repro.py"
- Then press 'c' to trigger the crash.
I'm not sure where the fix should happen: in IPython, or in ipdb? There was an attempt at fixing it on the ipdb side here: gotcha/ipdb#130 but it causes spewing to restart in the dumb shell since it relies on the prompt_toolkit eventloop.
Any suggestion of a fix? I'd really like to get ipdb + Emacs going :)
Activity
dmcooke commentedon Jul 22, 2017
I just ran into a similar error trying to use
IPython.terminal.debuggerwithpytest. I've triaged it down to(basically, running the debugger without a tty, forcing simple prompt mode). This fails with
In both cases,
TerminalPdbis attempting to use attributes ofself.shellthat don't exist when the shell is created in simple prompt mode. (I suspect that the OP is using a version before the fix for #10478 was added, otherwise he would fail at theself.shell.styleline also.)IPython.terminal.interactiveshell.TerminalShell:init_prompt_toolkitshould set the same attributes for simple prompt mode as for not; at the least, I see_style,style,_pt_app,_eventloopandpt_cli. It would appear that simple prompt mode would trigger other bugs, as the_pt_appandpt_cliattributes are used in some other methods ofTerminalShell.blueyed commentedon May 23, 2019
@dmcooke
Created a spearate issue about this: #11745