From ee7a1fc043c0d0cacc80951bc89e9118bdcb6062 Mon Sep 17 00:00:00 2001 From: Dpeta Date: Wed, 23 Mar 2022 18:32:59 +0100 Subject: [PATCH] Close log file descriptors after write (low ulimit platform) --- profile.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/profile.py b/profile.py index 3f1a951..d06278b 100644 --- a/profile.py +++ b/profile.py @@ -77,13 +77,23 @@ class PesterLog(object): PchumLog.debug("post-error msg") self.convos[handle][format] = fp + for (format, t) in modes.items(): f = self.convos[handle][format] - if platform.system() == "Windows": - f.write(t+"\r\n") - else: - f.write(t+"\r\n") + f.write(t+"\r\n") + + # flush + fsync force a write, might not be required though. + for (format, t) in modes.items(): f.flush() + os.fsync(f.fileno()) + + # This way the file descriptors are closed and reopened for every message, + # which is sub-optimal and definitely a performance drain but, + # otherwise we still run into the ulimit on platforms like MacOS fairly easily. + if ostools.isOSX() == True: + for (format, t) in modes.items(): + self.finish(handle) + def finish(self, handle): if handle not in self.convos: return