Skip to content

ipdb and "--simple-prompt" leads to an eventloop crash #10577

Open

Description

@apteryks

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).

  1. 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'
  1. In a terminal, start the IPython process in 'simple-prompt' mode like this:

ipython --simple-prompt -c "%run -d ipdb_eventloop_repro.py"

  1. 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

  1. added this to the wishlist milestone on May 23, 2017
  2. dmcooke commented on Jul 22, 2017

    @dmcooke

    I just ran into a similar error trying to use IPython.terminal.debugger with pytest. I've triaged it down to

    cat | python -c 'from IPython.terminal.debugger import set_trace; set_trace()'
    

    (basically, running the debugger without a tty, forcing simple prompt mode). This fails with

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 112, in set_trace
        TerminalPdb().set_trace(frame or sys._getframe().f_back)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 26, in __init__
        self.pt_init()
      File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/terminal/debugger.py", line 66, in pt_init
        style=self.shell.style
    AttributeError: 'TerminalInteractiveShell' object has no attribute 'style'
    

    In both cases, TerminalPdb is attempting to use attributes of self.shell that 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 the self.shell.style line also.)

    IPython.terminal.interactiveshell.TerminalShell:init_prompt_toolkit should set the same attributes for simple prompt mode as for not; at the least, I see _style, style, _pt_app, _eventloop and pt_cli. It would appear that simple prompt mode would trigger other bugs, as the _pt_app and pt_cli attributes are used in some other methods of TerminalShell.

  3. blueyed commented on May 23, 2019

    @blueyed
    Contributor

    @dmcooke
    Created a spearate issue about this: #11745

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions