Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

debugging - Exiting Python Debugger ipdb

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?

question from:https://stackoverflow.com/questions/32055062/exiting-python-debugger-ipdb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...