Issue #11444: Merge fix from 2.6.
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 2f081a0..aaad898 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -1627,6 +1627,7 @@
             h = wr()
             if h:
                 try:
+                    h.acquire()
                     h.flush()
                     h.close()
                 except (IOError, ValueError):
@@ -1635,6 +1636,8 @@
                     # references to them are still around at
                     # application exit.
                     pass
+                finally:
+                    h.release()
         except:
             if raiseExceptions:
                 raise