本文介绍了python:使用faulthandler有缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 3.3 包含一个名为 faulthandler 的模块,该模块在发生段错误时显示有用的回溯信息.(对于 3.3 之前的 Python 版本,模块可以从 PyPI 获得.)

Python 3.3 includes a module named faulthandler that displays helpful traceback information if a segfault occurs. (For Python versions prior to 3.3, the module can be obtained from PyPI.)

该模块默认不启用.它是这样启用的:

The module is not enabled by default. It is enabled like this:

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,管道,重要文件等,没有可靠的检测方法这种情况,因此在 Python 中默认不启用故障处理程序会更安全.

The reason is that faulthandler remembers the file descriptor of stderr, usually fd 2. The problem is that fd 2 may become something else, like a socket, a pipe, an important file, etc. There is no reliable way to detect this situation, and so it's safer to not enable faulthandler by default in Python.

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

faulthandler is safe in almost all cases, except when a file descriptor stored by faulthandler is replaced. Problem also described in the doc:https://docs.python.org/dev/library/faulthandler.html#issue-with-file-descriptors

注意:我写了故障处理程序.

Note: I wrote faulthandler.

这篇关于python:使用faulthandler有缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 10:07