当捕获信号时,我该如何迫使PDB退出?
PDB的退出命令通过提高异常(bdb.bdbquit
)来起作用。如果被抓住了这个例外,我将无法找到一种杀死该程序的方法,而没有杀死整个外壳。 CTRL+C通过提高键盘Interrupt
异常来起作用,这也可以抓住。
您可以使用此简单脚本来重新创建此问题。
foo = 0
while True:
try:
import pdb; pdb.set_trace()
foo += 1
except:
pass
使用退出命令或CTRL+c,该脚本无法从PDB内部停止。
我知道这是不良的编程,您绝对不应该使用,而没有异常类型。我之所以问,是因为我在调试时遇到了这个问题,第三方图书馆将我困在循环中。
PDB's quit command works by raising an exception (Bdb.BdbQuit
). If that exception gets caught, I cannot figure out a way to kill the program short of killing the entire shell. CTRL+C works by raising a KeyboardInterrupt
exception, which can also be caught.
You can recreate this problem with this simple script.
foo = 0
while True:
try:
import pdb; pdb.set_trace()
foo += 1
except:
pass
This script cannot be stopped from within PDB with the quit command or CTRL+C.
I'm aware this is bad programming and you should never use an except
without an exception type. I ask because I ran into this issue while debugging and a third-party library trapped me in the loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用
os.__exit
。
输出:
You can try killing the python process with
os._exit
.Output:
为什么不重新调整例外:
Why not re-raise the exception: