From c7121f9378ece850dbb7eedc148eb377b01a7343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 22 Aug 2022 14:13:07 +0200 Subject: [PATCH] profiler: Flush stdout before printing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently redirecting stderr to the same pipe as stdout does not guarantee that the data will not be mangled together. Flushing stdout before the profiler data is printed should ensure that it does not end up in the middle of some RPM path. Fixes: https://pagure.io/pungi/issue/1627 Signed-off-by: Lubomír Sedlář --- pungi/profiler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pungi/profiler.py b/pungi/profiler.py index 3ffef8b9..ed05c54f 100644 --- a/pungi/profiler.py +++ b/pungi/profiler.py @@ -69,6 +69,11 @@ class Profiler(object): @classmethod def print_results(cls, stream=sys.stdout): + # Ensure all data that was printed to stdout was already flushed. If + # the caller is redirecting stderr to stdout, and there's buffered + # data, we may end up in a situation where the stderr output printed + # below ends up mixed with the stdout lines. + sys.stdout.flush() print("Profiling results:", file=stream) results = cls._data.items() results = sorted(results, key=lambda x: x[1]["time"], reverse=True)