diff Python/pythonrun.c @ 66137:06f76ef27f86

Issue #10372: Import the warnings module only after the IO library is initialized, so as to avoid bootstrap issues with the '-W' option.
author Antoine Pitrou <solipsis@pitrou.net>
date Wed, 10 Nov 2010 13:55:25 +0000
parents ea14977a36de
children 6eabf8c1a75c
line wrap: on
line diff
--- a/Python/pythonrun.c	Wed Nov 10 08:59:25 2010 +0000
+++ b/Python/pythonrun.c	Wed Nov 10 13:55:25 2010 +0000
@@ -299,19 +299,21 @@
     if (install_sigs)
         initsigs(); /* Signal handling stuff, including initintr() */
 
-    /* Initialize warnings. */
-    if (PySys_HasWarnOptions()) {
-        PyObject *warnings_module = PyImport_ImportModule("warnings");
-        if (!warnings_module)
-            PyErr_Clear();
-        Py_XDECREF(warnings_module);
-    }
-
     initmain(); /* Module __main__ */
     if (initstdio() < 0)
         Py_FatalError(
             "Py_Initialize: can't initialize sys standard streams");
 
+    /* Initialize warnings. */
+    if (PySys_HasWarnOptions()) {
+        PyObject *warnings_module = PyImport_ImportModule("warnings");
+        if (warnings_module == NULL) {
+            fprintf(stderr, "'import warnings' failed; traceback:\n");
+            PyErr_Print();
+        }
+        Py_XDECREF(warnings_module);
+    }
+
     if (!Py_NoSiteFlag)
         initsite(); /* Module site */
 }