From 6853b014e43c254033bb79917ac4e4615a9484a0 Mon Sep 17 00:00:00 2001 From: Marco Magni <150774048+magni5@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:12:45 +0000 Subject: [PATCH] immediately free up file handle fo re-use --- src/pynetlogo/core.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pynetlogo/core.py b/src/pynetlogo/core.py index f45edce..4553dd5 100644 --- a/src/pynetlogo/core.py +++ b/src/pynetlogo/core.py @@ -509,10 +509,9 @@ def repeat_report(self, netlogo_reporter, reps, go="go", include_t0=True): # TODO issue #55 commands = [] fns = {} - fhs = [] for variable in cols: fh, fn = tempfile.mkstemp(suffix=".txt", dir=tempfolder) - fhs.append(fh) + os.close(fh) #immediately free up file handle for re-use fns[variable] = fn fn = '"{}"'.format(fn) fn = fn.replace(os.sep, "/") @@ -555,9 +554,6 @@ def repeat_report(self, netlogo_reporter, reps, go="go", include_t0=True): results[key] = result # cleanup temp files and folders - for fh in fhs: - os.close(fh) #free up file handle for re-use - for key, value in fns.items(): os.remove(value) #delete file by name