python:使用故障处理程序有缺点吗?

标签 python python-3.x python-3.3 traceback faulthandler

Python 3.3 包含一个名为 faulthandler 的模块,如果发生段错误,它会显示有用的回溯信息。 (对于 Python 3.3 之前的版本,模块可以是 obtained from PyPI 。)

默认情况下不启用该模块。它是这样启用的:

import faulthandler
faulthandler.enable()

这个功能非常有用。默认情况下未启用它是否有任何特殊原因?它对性能有任何负面影响吗?

最佳答案

This feature is very useful. Is there any particular reason it isn't enabled by default? Does it have any negative effects on performance?

原因是faulthandler会记住stderr的文件描述符,通常是fd 2。问题是fd 2可能会变成别的东西,像socket,pipe,重要的文件等等,没有可靠的检测方式这种情况,因此在 Python 中默认不启用故障处理程序会更安全。

faulthandler 在几乎所有情况下都是安全的,除非 faulthandler 存储的文件描述符被替换。文档中还描述了问题: https://docs.python.org/dev/library/faulthandler.html#issue-with-file-descriptors

注意:我写的是faulthandler。

关于python:使用故障处理程序有缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21733856/

相关文章:

Python xlrd 模块

python - 打印列表项和索引

python - 通过模拟在单元测试上运行coverage.py

python-3.x - python :find a number in a list (smaller but the biggest one)

python - 如何让程序回到代码的顶部而不是关闭

python - 在 C++ 中嵌入 Python 时我要链接到什么

python-3.x - 我的 scipy.misc 模块似乎缺少 imsave

python - 求和范围的时间复杂度

python - 在嵌套列表上使用删除

python - 使用参数(对象数组)从 python2 脚本调用 python3 方法并接收输出