I use ipdb fairly often in a way to just jump to a piece of code that is isolated i.e. it is hard to write a real script that uses it. Instead I write a minimal test case with mocking and jump into it.
Exemplary for the workflow:
def func(): ... import ipdb ipdb.set_trace() ... def test_case(): ... func() ...
Then, invoke
py.test test_file.py -s -k test_case
Now, usually I just check one variable or two, and then want to quit. Change the code and do it over again.
How do I quit? The manual says q
quits the debugger. It doesn't (really). You have to quit a few times before the debugger actually terminates. The same behavior for Ctrl-C and Ctrl-D (with the additional frustration that hitting Ctrl-D several times eventually quits the terminal, too).
Is there a smart way to force quit? Is this workflow even sensible? What is the standard way to do it?
If you enter pdb interactive mode there is no way to return to ipdb or ipython. The proper way to exit is by using ctrl-d .
The Python debugger will automatically start over when it reaches the end of your program. Whenever you want to leave the pdb console, type the command quit or exit .
ipdb, the IPython-enabled Python Debugger, is a third party interative debugger with all pdb's functionality and adds IPython support for the interactive shell, like tab completion, color support, magic functions and much more. You use ipdb just as you use pdb but with an enhanced user experience.
ipdb, the IPython-enabled Python Debugger, is a third party interative debugger with all pdb’s functionality and adds IPython support for the interactive shell, like tab completion, color support, magic functions and much more. You use ipdb just as you use pdb but with an enhanced user experience.
As mentioned in another answer, this was a bug in IPython 5.1. It was fixed in this pull request and is no longer an issue from IPython 5.2 and onwards. You can now use q, quit (), or Ctrl + d to exit the debugger.
Searching for a better approach to debug code, there is always something better available out there, I came across pdb and ipdb. pdb, the Python Debugger, is an interactive debugger that is part of the Python standard library.
Insert the following code at the location where you want to break into the debugger: When the line above is executed, Python stops and waits for you to tell it what to do next. You’ll see a (Pdb) prompt. This means that you’re now paused in the interactive debugger and can enter a command.
I put the following in my .pdbrc
import os alias kk os.system('kill -9 %d' % os.getpid())
kk
kills the debugger and (the process that trigger the debugger).
The following worked for me:
import sys sys.exit()
On newer versions of ipython, as mentioned above and below, this doesn't work. In that case,
import os os._exit(0)
should still do the trick.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With