From 6b7cfea190d5147ab1a13733bff202e1a92fe6a6 Mon Sep 17 00:00:00 2001 From: Donny Greenberg Date: Fri, 12 Apr 2024 07:18:22 -0400 Subject: [PATCH] Fix call logging by unbuffering stdout/err in call threadpool (#724) Because we started running method calls in a threadpool, the output was buffered and only flushed/printed at the end (https://stackoverflow.com/questions/18234469/python-multithreaded-print-statements-delayed-until-all-threads-complete-executi). This changes the StreamTee utility we use to print stdout/logging to flush on each write, per https://mail.python.org/pipermail/tutor/2003-November/026645.html --- runhouse/resources/provenance.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/runhouse/resources/provenance.py b/runhouse/resources/provenance.py index 0650f4aa5..46f904ea9 100644 --- a/runhouse/resources/provenance.py +++ b/runhouse/resources/provenance.py @@ -527,6 +527,15 @@ def write(self, message): for stream in self.outstreams: if message: stream.write(message) + # We flush here to ensure that the logs are written to the file immediately + # see https://github.com/run-house/runhouse/pull/724 + stream.flush() + + def writelines(self, lines): + self.instream.writelines(lines) + for stream in self.outstreams: + stream.writelines(lines) + stream.flush() def flush(self): self.instream.flush()