[Python-checkins] r87756 - python/branches/py3k/Lib/test/regrtest.py

victor.stinner python-checkins at python.org
Wed Jan 5 04:54:26 CET 2011


Author: victor.stinner
Date: Wed Jan  5 04:54:26 2011
New Revision: 87756

Log:
regrtest: close the new stdout and restore the original stdout at exit

Fix a ResourceWarning(unclosed file).

Modified:
   python/branches/py3k/Lib/test/regrtest.py

Modified: python/branches/py3k/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k/Lib/test/regrtest.py	(original)
+++ python/branches/py3k/Lib/test/regrtest.py	Wed Jan  5 04:54:26 2011
@@ -743,10 +743,19 @@
     if os.name == "nt":
         # Replace sys.stdout breaks the stdout newlines on Windows: issue #8533
         return
+
+    import atexit
+
     stdout = sys.stdout
     sys.stdout = open(stdout.fileno(), 'w',
         encoding=stdout.encoding,
-        errors="backslashreplace")
+        errors="backslashreplace",
+        closefd=False)
+
+    def restore_stdout():
+        sys.stdout.close()
+        sys.stdout = stdout
+    atexit.register(restore_stdout)
 
 def runtest(test, verbose, quiet,
             huntrleaks=False, debug=False, use_resources=None):


More information about the Python-checkins mailing list