Skip to content

Commit

Permalink
Better closing of files
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Feb 20, 2024
1 parent e58aecf commit f19ab2d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lems/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def include_file(self, path, include_dirs=[]):
parser = LEMSFileParser(self, inc_dirs, self.include_includes)
if os.access(path, os.F_OK):
if not path in self.included_files:
parser.parse(open(path).read())
with open(path) as f:
parser.parse(f.read())
self.included_files.append(path)
return
else:
Expand All @@ -284,7 +285,8 @@ def include_file(self, path, include_dirs=[]):
new_path = inc_dir + "/" + path
if os.access(new_path, os.F_OK):
if not new_path in self.included_files:
parser.parse(open(new_path).read())
with open(new_path) as f:
parser.parse(f.read())
self.included_files.append(new_path)
return
else:
Expand Down Expand Up @@ -376,7 +378,9 @@ def export_to_file(self, filepath, level_prefix=" "):

f = open(filepath, "w")
f.write(xmlstr)
f.close()
f.flush()
os.fsync(f.fileno())


def resolve(self) -> lems.model.Model:
"""
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = PyLEMS
version = 0.6.5
version = 0.6.6
author = PyLEMS authors and contributors
author_email = gautham@lisphacker.org, p.gleeson@gmail.com
maintainer_email = p.gleeson@gmail.com
Expand Down

0 comments on commit f19ab2d

Please sign in to comment.