From f19ab2df1fffb4e137225aa5cc1ecf48bb2d0711 Mon Sep 17 00:00:00 2001 From: pgleeson Date: Tue, 20 Feb 2024 18:54:24 +0000 Subject: [PATCH] Better closing of files --- lems/model/model.py | 10 +++++++--- setup.cfg | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lems/model/model.py b/lems/model/model.py index 527bd91..cbe2d74 100644 --- a/lems/model/model.py +++ b/lems/model/model.py @@ -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: @@ -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: @@ -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: """ diff --git a/setup.cfg b/setup.cfg index a84acf1..6806b45 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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