Issue #15781: Fix two small race conditions in import's module locking.
diff --git a/Python/import.c b/Python/import.c
index 2540f9d..2f71b97 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -1408,7 +1408,11 @@
         int initializing = 0;
 
         Py_INCREF(mod);
-        /* Only call _bootstrap._lock_unlock_module() if __initializing__ is true. */
+        /* Optimization: only call _bootstrap._lock_unlock_module() if
+           __initializing__ is true.
+           NOTE: because of this, __initializing__ must be set *before*
+           stuffing the new module in sys.modules.
+         */
         value = _PyObject_GetAttrId(mod, &PyId___initializing__);
         if (value == NULL)
             PyErr_Clear();