diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-01-05 03:54:26 +0000 |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-01-05 03:54:26 +0000 |
commit | f024bc1c2ee5fabfcae4beab32c387ccbe21d78c (patch) | |
tree | a1e31d388adf8afea5010f1efdc04417eb06fe18 | |
parent | 96475d809ec140437b4ab4c6524150e4fda93d28 (diff) | |
download | cpython-f024bc1c2ee5fabfcae4beab32c387ccbe21d78c.tar.gz |
regrtest: close the new stdout and restore the original stdout at exit
Fix a ResourceWarning(unclosed file).
-rwxr-xr-x | Lib/test/regrtest.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 1649865ecc..92d1597c62 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -743,10 +743,19 @@ def replace_stdout(): 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): |