profiler: Flush stdout before printing

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ář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2022-08-22 14:13:07 +02:00 committed by lsedlar
parent 146b88e1e9
commit c7121f9378
1 changed files with 5 additions and 0 deletions

View File

@ -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)