From 425dee1afa4140572281dd025578ce8a71b5978e Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 9 Feb 2015 13:06:33 -0800 Subject: [PATCH] Close some file handles explicitly in facts.py Helps control open file descriptor count with pypy (which is used with one coreos + ansible example). Part of a fix for https://github.com/ansible/ansible/issues/10157 --- lib/ansible/module_utils/facts.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index c2d7b652e1..ff4e6d990d 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2502,9 +2502,13 @@ class SunOSVirtual(Virtual): def get_file_content(path, default=None): data = default if os.path.exists(path) and os.access(path, os.R_OK): - data = open(path).read().strip() - if len(data) == 0: - data = default + try: + datafile = open(path) + data = datafile.read().strip() + if len(data) == 0: + data = default + finally: + datafile.close() return data def ansible_facts(module):