python - 当信号处理程序中遇到异常时,如何使 Django 信号处理程序不会静默失败?

标签 python django error-handling

当处理程序中遇到异常时,如何使 Django 信号处理程序不会静默失败

在使用开发服务器时是否有记录所有这些错误的地方

为什么 django 信号处理程序无论如何都会默默地失败?是不是违反了Zen of Python中的一句话?

Zen of Python clearly states...

Errors should never pass silently.

这使它们成为调试的噩梦。你所看到的只是信号没有被触发......

我找到了 this问题,但答案对我来说没用,因为它对问题非常具体(答案建议使用 pyflakes,我已经使用 pydev 可以进行令人满意的静态分析)

最佳答案

是的,错误永远不会失败

是的,我的想法和你一样:错误永远不应该默默地失败

内置信号不会静默失败

Django 的内置信号不会静默失败,因为它们使用 send()

只有 send_robust() 会忽略异常

来自 send_robust() 的文档

send_robust() catches all errors derived from Python’s Exception class, and ensures all receivers are notified of the signal. If an error occurs, the error instance is returned in the tuple pair for the receiver that raised the error.

结论

由于 django 不使用 send_robust(),请调查它被调用的位置。我猜它在您的源代码中,或者在第三方应用程序的代码中。

关于python - 当信号处理程序中遇到异常时,如何使 Django 信号处理程序不会静默失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14481225/

相关文章:

python - pip 安装选项 "no-cache-dir"和 "target"不能很好地协同工作?

python - django unicode 转换为日语

python - 如何将 formbuilder 制作的表单添加到 Wagtail 中的每个页面?

ruby - 当我的脚本中断时,如何让 shell/ruby 发出声音(让我的电脑发出哔哔声或播放声音/音轨)?

error-handling - 如何正确打印来自 `luaL_dostring()`的错误消息?

python - AttributeError : 'NoneType' object has no attribute 'text' , but text is on page

python - 嵌套for循环慢速python计算特殊标准差

python - 使用交互改变另一个参数时重置参数

Python TDD目录结构

python - 复制项目后,Django 安装选择了错误的迁移路径名