Search code examples
pythondebuggingpdb

ipdb requires Ctrl+D for processing command


I am debugging my Python scripts with ipdb. Somehow I have the problem, that after entering a command, for instance n, s, c, b etc. I have to press Ctrl+D two times in order for ipdb to process the command and proceed.

Any idea what causes this and how I can turn it off?


Solution

  • This effect is not isolated to ipdb:

    Technically Ctrl-D terminates transmission, and only raises EOF if this results in an empty input buffer. Which only happens when you press Ctrl-D before inputting any characters.

    Do this experiment:

    1.  At the linux terminal type cat
    2.  press enter once.
    3.  enter letters: foo
    4.  press <Ctrl-D> once, you don't get back to the terminal.
    5.  press <Ctrl-D> again, you are brought back to the terminal.
    

    So it looks like this:

    user@defiant ~ $ cat
    foofoouser@defiant ~ $
    

    foo is printed twice because the first time you pressed it flushed your input. The second time it's interpreted as end the program.

    How to stop this behavior:

    Don't be connected to a TTY when you are pressing Ctrl-D. Which means don't use a normal linux terminal. Not sure if this is even possible.

    How to process a command in ipdb

    Pressing enter should process the command as illustrated by the video here: http://www.gregaker.net/2012/apr/05/debugging-python-with-pdb-or-ipdb/