From a5c17eae4d5197d423a8fcef40b1d31e74439772 Mon Sep 17 00:00:00 2001 From: Mats Wichmann Date: Mon, 13 Aug 2018 14:55:01 -0600 Subject: Quiet Py3.6+ ResourceWarnings on tests When a test calls _subproc to set up a subprocess.Popen call, if the arg vector contains the string 'devnull' os.devnull is opened and the resulting file object is stored in the kw vector prior to passing it to Popen. Reigster a close() call with atexit in this case. Eliminates a lot of Python 3.6+ ResourceWarning messages - 336 on this machine. Signed-off-by: Mats Wichmann --- src/CHANGES.txt | 1 + src/engine/SCons/Action.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 6534f3a..7c5abba 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -120,6 +120,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - quiet py3 warning in UtilTests.py - fix tests specifying octal constants for py3 - fix must_contain tests for py3 + - if test opens os.devnull, register with atexit so file opens do not leak. From Hao Wu - typo in customized decider example in user guide diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index b44088b..249363f 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -107,6 +107,7 @@ import sys import subprocess import itertools import inspect +import atexit import SCons.Debug from SCons.Debug import logInstanceCreation @@ -772,12 +773,15 @@ def _subproc(scons_env, cmd, error = 'ignore', **kw): io = kw.get('stdin') if is_String(io) and io == 'devnull': kw['stdin'] = open(os.devnull) + atexit.register(kw['stdin'].close) io = kw.get('stdout') if is_String(io) and io == 'devnull': kw['stdout'] = open(os.devnull, 'w') + atexit.register(kw['stdout'].close) io = kw.get('stderr') if is_String(io) and io == 'devnull': kw['stderr'] = open(os.devnull, 'w') + atexit.register(kw['stderr'].close) # Figure out what shell environment to use ENV = kw.get('env', None) -- cgit v0.12