Skip to content

Commit

Permalink
Close some file handles explicitly in facts.py
Browse files Browse the repository at this point in the history
Helps control open file descriptor count with pypy (which is used with
one coreos + ansible example).  Part of a fix for
#10157
  • Loading branch information
abadger committed Feb 9, 2015
1 parent 9db17af commit 425dee1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/ansible/module_utils/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2502,9 +2502,13 @@ def get_virtual_facts(self):
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):
Expand Down

0 comments on commit 425dee1

Please sign in to comment.