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

Fix a ResourceWarning(unclosed file).
This commit is contained in:
Victor Stinner 2011-01-05 03:54:26 +00:00
parent 358e11d928
commit 4b2b43d988
1 changed files with 10 additions and 1 deletions

View File

@ -743,10 +743,19 @@ def replace_stdout():
if os.name == "nt": if os.name == "nt":
# Replace sys.stdout breaks the stdout newlines on Windows: issue #8533 # Replace sys.stdout breaks the stdout newlines on Windows: issue #8533
return return
import atexit
stdout = sys.stdout stdout = sys.stdout
sys.stdout = open(stdout.fileno(), 'w', sys.stdout = open(stdout.fileno(), 'w',
encoding=stdout.encoding, 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, def runtest(test, verbose, quiet,
huntrleaks=False, debug=False, use_resources=None): huntrleaks=False, debug=False, use_resources=None):