Python VS Code 调试 - 捕获 SIGTERM? [英] Python VS Code Debug - Capture SIGTERM?
问题描述
我想在 python 调试器停止时强制 sys.exit()
.当我停止调试器时,我看到 Terminated: 15
所以我假设这是 SIGTERM
.但是,当停止调试器时,我的 kill 函数没有被调用.
I'd like to force sys.exit()
when the python debugger is stopped. When I stop the debugger I see Terminated: 15
so I assume this is SIGTERM
. However, when stopping the debugger, my kill function isn't called.
def kill(sig, frame):
sys.exit(0)
signal.signal(signal.SIGINT, kill)
signal.signal(signal.SIGTERM, kill)
停止vscode调试器时,发送了什么信号?
When stopping the vscode debugger, what signal is sent?
刚刚尝试了所有这些.没有爱
Just tried all of them. No love
for s in signal.Signals:
try:
signal.signal(s, self._kill)
except:
pass
推荐答案
现在我们似乎是 OOL(运气不好) - 我遇到了同样的问题,发现 VS Code python 扩展确实在调试停止时发出 SIGKILL,不能咳.
For now we seem to be OOL (out of luck) - I ran into the same issue and found that VS Code python extension does issue a SIGKILL on debug stop, which cannot be cought.
与 node.js 扩展不同,Python 扩展也不支持将类型设置为 SIGTERM 或 SIGINT.
Unlike the node.js extenstion, the Python extension also does not support setting the type to SIGTERM or SIGINT.
我发现的唯一解决方法是在 VS Code 中打开一个终端(类型:Pythen Debug Terminal).它应该在调试期间显示 python 命令行为和输出.通过单击终端并手动按 ctrl-C 使终端成为焦点.这应该会优雅地停止调试的程序,并且您可以捕获 SIGTERM 或 SIGINT.
The only workaround I found is to have an open terminal (type: Pythen Debug Terminal) in VS Code. It should show the python command behavior and output during debug. Bring the terminal into focus by clicking on it and press ctrl-C manually. This should stop the debugged program gracefully and your catching the SIGTERM or SIGINT will work.
这篇关于Python VS Code 调试 - 捕获 SIGTERM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!