Ok, here is a full patch tested on Linux and Windows:
- Add faulthandler module (code, doc, tests) as a builtin module
- Add "-X faulthandler=1" command line option and PYTHONFAULTHANDLER=1 en var to enable the fault handler at startup
- Add _Py_DumpTraceback() and _Py_DumpTracebackThreads() functions to Python/traceback.c
- Py_FatalError() calls _Py_DumpTraceback() if there is not exception
- Initialize/Unload faulthandler explicitly in Py_InitializeEx()/Py_Finalize() to do it in the right order
I added a section in the doc to explain the file descriptor issue.
I merged different .c and .h files into faulthandler.c, the code is easier to read and maintain like that.
I don't know if the following test is the best test to check if SIGARLM constant and alarm() function are available:
+#ifdef SIGALRM
+# define FAULTHANDLER_LATER
+#endif
(The test works at least on Linux and Windows)