Prevent crash on shutdown which can occur if we are finalizing
and the module dict has been cleared already and some object
raises a warning (like in a __del__).

Will backport.
diff --git a/Misc/NEWS b/Misc/NEWS
index f3749ab..b1a794b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
 Core and builtins
 -----------------
 
+- Prevent seg fault on shutdown which could occur if an object
+  raised a warning.
+
 - Bug #1566280: Explicitly invoke threading._shutdown from Py_Main,
   to avoid relying on atexit.