Issue #13444: When stdout has been closed explicitly, we should not attempt to flush it at shutdown and print an error.

This also adds a test for issue #5319, whose resolution introduced the issue.
diff --git a/Misc/NEWS b/Misc/NEWS
index fba2c3d..eaadaaf 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -83,6 +83,9 @@
 Library
 -------
 
+- Issue #13444: When stdout has been closed explicitly, we should not attempt
+  to flush it at shutdown and print an error.
+
 - Issue #12856: Ensure child processes do not inherit the parent's random
   seed for filename generation in the tempfile module.  Patch by Brian
   Harring.