# HG changeset patch # User Kyle Lippincott # Date 2020-01-28 02:16:05 # Node ID d6d4170882cd8b8ed4d2b67d69bbb46d4c54cb32 # Parent 732098027b34860f5fb76809b69c8251f05d3821 profiling: flush stdout before writing profile to stderr On py3, stdout and stderr appear to be buffered and this causes my command's output to be intermixed with the profiling output. Differential Revision: https://phab.mercurial-scm.org/D8024 diff --git a/mercurial/profiling.py b/mercurial/profiling.py --- a/mercurial/profiling.py +++ b/mercurial/profiling.py @@ -186,6 +186,7 @@ class profile(object): self._output = None self._fp = None self._fpdoclose = True + self._flushfp = None self._profiler = None self._enabled = enabled self._entered = False @@ -246,6 +247,8 @@ class profile(object): else: self._fpdoclose = False self._fp = self._ui.ferr + # Ensure we've flushed fout before writing to ferr. + self._flushfp = self._ui.fout if proffn is not None: pass @@ -265,6 +268,7 @@ class profile(object): def __exit__(self, exception_type, exception_value, traceback): propagate = None if self._profiler is not None: + self._uiflush() propagate = self._profiler.__exit__( exception_type, exception_value, traceback ) @@ -280,3 +284,7 @@ class profile(object): def _closefp(self): if self._fpdoclose and self._fp is not None: self._fp.close() + + def _uiflush(self): + if self._flushfp: + self._flushfp.flush()