python: Is there a downside to using faulthandler?

Question:

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?

Asked By: Stuart Berg

||

Answers:

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.

Answered By: vstinner