From f03e71927887e396bbe6ae7ca1d50587f19dbf5c Mon Sep 17 00:00:00 2001 From: Michka Popoff Date: Tue, 26 Apr 2016 00:08:10 +0200 Subject: [PATCH] Close subprocess stdout stream once value has been read Fixes the following warnings with python3: Exception ignored in: <_io.FileIO name=4 mode='rb' closefd=True> ResourceWarning: unclosed file <_io.BufferedReader name=4> --- docs/history.rst | 3 +++ pygccxml/parser/config.py | 1 + pygccxml/utils/utils.py | 3 +++ unittests/file_cache_tester.py | 1 + 4 files changed, 8 insertions(+) diff --git a/docs/history.rst b/docs/history.rst index 8dbe2ee7..b48e8e4d 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -17,6 +17,9 @@ Version 1.7.4 (not yet released) 1. Since this release, pyggcxml's version numbers do not contain the ``v`` prefix anymore. This was breaking distribution on PyPI (pypi.python.org). +2. Close subprocess stdout stream once value has been read. + Fixes some warnings under python3. + Version 1.7.3 ------------- diff --git a/pygccxml/parser/config.py b/pygccxml/parser/config.py index ca6590ba..2f255ed3 100644 --- a/pygccxml/parser/config.py +++ b/pygccxml/parser/config.py @@ -452,6 +452,7 @@ def create_compiler_path(xml_generator, compiler_path): p = subprocess.Popen( ['which', 'clang++'], stdout=subprocess.PIPE) compiler_path = p.stdout.read().decode("utf-8").rstrip() + p.stdout.close() # No clang found; use gcc if compiler_path == '': compiler_path = '/usr/bin/c++' diff --git a/pygccxml/utils/utils.py b/pygccxml/utils/utils.py index 0d7c92be..93af6fa6 100644 --- a/pygccxml/utils/utils.py +++ b/pygccxml/utils/utils.py @@ -50,13 +50,16 @@ def find_xml_generator(name=None): name = "gccxml" p = subprocess.Popen([command, name], stdout=subprocess.PIPE) path = p.stdout.read().decode("utf-8") + p.stdout.close() if path == "": name = "castxml" p = subprocess.Popen([command, name], stdout=subprocess.PIPE) path = p.stdout.read().decode("utf-8") + p.stdout.close() else: p = subprocess.Popen([command, name], stdout=subprocess.PIPE) path = p.stdout.read().decode("utf-8") + p.stdout.close() if path == "": raise(Exception( "No c++ parser found. Please install castxml or gccxml.")) diff --git a/unittests/file_cache_tester.py b/unittests/file_cache_tester.py index 8dd7a3f2..b96f18c9 100644 --- a/unittests/file_cache_tester.py +++ b/unittests/file_cache_tester.py @@ -89,6 +89,7 @@ def test_reopen_cache(self): [sys.executable, "unittests/reopen_cache_tester.py"], stdout=subprocess.PIPE) print(p.stdout.read()) + p.stdout.close() def create_suite():