退出Python Debugger ipdb [英] Exiting Python Debugger ipdb
问题描述
我经常使用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.
工作流示例:
def func():
...
import ipdb
ipdb.set_trace()
...
def test_case():
...
func()
...
然后,调用
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.
我如何退出?该手册说 q
退出调试器。它不(真的)。在调试器实际终止之前,您必须退出几次。 Ctrl-C和Ctrl-D的同样行为(带有Ctrl-D几次的额外挫折最终也会终止终端)。
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?
推荐答案
我将以下内容放在我的 .pdbrc
I put the following in my .pdbrc
import os
alias kk os.system('kill -9 %d' % os.getpid())
kk
杀死调试器和(触发调试器的过程)。
kk
kills the debugger and (the process that trigger the debugger).
这篇关于退出Python Debugger ipdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!