python: Is there a downside to using faulthandler?

青春壹個敷衍的年華 提交于 2021-02-04 10:39:20

问题


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?


回答1:


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

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 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.



来源:https://stackoverflow.com/questions/21733856/python-is-there-a-downside-to-using-faulthandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!