Fix initialization of the faulthandler module
faulthandler requires the importlib if "-X faulthandler" option is present on
the command line, so initialize faulthandler after importlib.
Add also an unit test.
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 6ee9a5f..cafc09a 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -356,10 +356,6 @@
_PyImportHooks_Init();
- /* initialize the faulthandler module */
- if (_PyFaulthandler_Init())
- Py_FatalError("Py_Initialize: can't initialize faulthandler");
-
/* Initialize _warnings. */
_PyWarnings_Init();
@@ -368,6 +364,10 @@
import_init(interp, sysmod);
+ /* initialize the faulthandler module */
+ if (_PyFaulthandler_Init())
+ Py_FatalError("Py_Initialize: can't initialize faulthandler");
+
_PyTime_Init();
if (initfsencoding(interp) < 0)