Disable output buffering in devtools scripts. Rather than adding .flush() calls manually after each printout, this disables output buffering in devtools scripts altogether. R=qsr@chromium.org Review URL: https://codereview.chromium.org/1964903002 .
diff --git a/mojo/devtools/common/devtoolslib/android_shell.py b/mojo/devtools/common/devtoolslib/android_shell.py index daa2443..ca7d5c1 100644 --- a/mojo/devtools/common/devtoolslib/android_shell.py +++ b/mojo/devtools/common/devtoolslib/android_shell.py
@@ -395,7 +395,6 @@ host_port = self._forward_host_port_to_device(0, device_port) print ('Dart observatory available at the host at http://127.0.0.1:%d' % host_port) - sys.stdout.flush() logcat_watch_thread = threading.Thread( target=_forward_observatories_as_needed)
diff --git a/mojo/devtools/common/devtoolslib/utils.py b/mojo/devtools/common/devtoolslib/utils.py index 7bf2e1c..085d225 100644 --- a/mojo/devtools/common/devtoolslib/utils.py +++ b/mojo/devtools/common/devtoolslib/utils.py
@@ -4,6 +4,9 @@ """Python utils.""" +import os +import sys + def overrides(parent_class): """Inherits the docstring from the method of the same name in the indicated @@ -14,3 +17,11 @@ method.__doc__ = getattr(parent_class, method.__name__).__doc__ return method return overriding + + +def disable_output_buffering(): + """Disables the buffering of the stdout. Devtools command line scripts should + do so, so that their stdout is consistent when not directly attached to a + terminal (e.g. because another script runs devtools in a subprocess). + """ + sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
diff --git a/mojo/devtools/common/mojo_benchmark b/mojo/devtools/common/mojo_benchmark index e01ff62..0c1dcd9 100755 --- a/mojo/devtools/common/mojo_benchmark +++ b/mojo/devtools/common/mojo_benchmark
@@ -15,6 +15,7 @@ from devtoolslib import perf_dashboard from devtoolslib import shell_arguments from devtoolslib import shell_config +from devtoolslib.utils import disable_output_buffering _DESCRIPTION = """Runner for Mojo application benchmarks. @@ -145,6 +146,7 @@ def main(): + disable_output_buffering() parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=_DESCRIPTION)
diff --git a/mojo/devtools/common/mojo_run b/mojo/devtools/common/mojo_run index 43f83be..72fc047 100755 --- a/mojo/devtools/common/mojo_run +++ b/mojo/devtools/common/mojo_run
@@ -9,6 +9,7 @@ from devtoolslib import shell_arguments from devtoolslib import shell_config +from devtoolslib.utils import disable_output_buffering _DESCRIPTION = """Runner for Mojo applications. @@ -48,6 +49,7 @@ def main(): + disable_output_buffering() logging.basicConfig() parser = argparse.ArgumentParser(
diff --git a/mojo/devtools/common/mojo_test b/mojo/devtools/common/mojo_test index 59f5310..eca37f3 100755 --- a/mojo/devtools/common/mojo_test +++ b/mojo/devtools/common/mojo_test
@@ -17,6 +17,7 @@ from devtoolslib import apptest_gtest from devtoolslib import shell_arguments from devtoolslib import shell_config +from devtoolslib.utils import disable_output_buffering _DESCRIPTION = """Runner for Mojo application tests. @@ -59,6 +60,7 @@ def main(): + disable_output_buffering() parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=_DESCRIPTION) @@ -102,7 +104,6 @@ _logger.info("Will start: %s" % test_name) print "Running %s...." % test_name, - sys.stdout.flush() if test_type == "dart": apptest_result = apptest_dart.run_dart_apptest(shell, shell_args, test,