From 4a3e56075ec3190885c02563a525992e34fa0130 Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Wed, 2 Feb 2022 16:19:10 +0100 Subject: [PATCH] Switch to universal_newlines=True. To fix the blocking issue this CL uses universal_newlines (removing the calls to decode('utf-8')). Tested locally. No-Presubmit: True Bug: webrtc:13607 Change-Id: Ib56cf87c8f903087d0c4aa09b58c464edac649c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250222 Auto-Submit: Mirko Bonadei Commit-Queue: Mirko Bonadei Reviewed-by: Jeremy Leconte Commit-Queue: Jeremy Leconte Reviewed-by: Christoffer Jansson Cr-Commit-Position: refs/heads/main@{#35889} --- audio/test/low_bandwidth_audio_test.py | 35 ++++++++------------------ 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/audio/test/low_bandwidth_audio_test.py b/audio/test/low_bandwidth_audio_test.py index 107ebbf3f7..051d67fea4 100755 --- a/audio/test/low_bandwidth_audio_test.py +++ b/audio/test/low_bandwidth_audio_test.py @@ -123,14 +123,14 @@ def ExtractTestRuns(lines, echo=False): """ for line in lines: if echo: - sys.stdout.write(line.decode('utf-8')) + sys.stdout.write(line) # Output from Android has a prefix with the device name. android_prefix_re = r'(?:I\b.+\brun_tests_on_device\((.+?)\)\s*)?' test_re = r'^' + android_prefix_re + (r'TEST (\w+) ([^ ]+?) ([^\s]+)' r' ?([^\s]+)?\s*$') - match = re.search(test_re, line.decode('utf-8')) + match = re.search(test_re, line) if match: yield match.groups() @@ -177,31 +177,14 @@ def _RunPesq(executable_path, # Need to provide paths in the current directory due to a bug in PESQ: # On Mac, for some 'path/to/file.wav', if 'file.wav' is longer than # 'path/to', PESQ crashes. - # The bufsize is set to 0 to keep the default Python 2.7 behaviour (it - # changed to -1 in Python >3.3.1 but this is causing issues). - process = subprocess.Popen(_LogCommand(command), - bufsize=0, - cwd=directory, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - - try: - logging.info('Waiting for termination ...') - out, err = process.communicate(timeout=120) - except TimeoutExpired: - logging.error('Timeout, killing the process.') - process.kill() - out, err = process.communicate() - - if process.returncode != 0: - logging.error('%s (exit_code: %d)', - err.decode('utf-8').strip(), process.returncode) - return {} + out = subprocess.check_output(_LogCommand(command), + cwd=directory, + universal_newlines=True, + stderr=subprocess.STDOUT) # Find the scores in stdout of PESQ. match = re.search( - r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', - out.decode('utf-8')) + r'Prediction \(Raw MOS, MOS-LQO\):\s+=\s+([\d.]+)\s+([\d.]+)', out) if match: raw_mos, _ = match.groups() return {'pesq_mos': (raw_mos, 'unitless')} @@ -216,12 +199,13 @@ def _RunPolqa(executable_path, reference_file, degraded_file): degraded_file ] process = subprocess.Popen(_LogCommand(command), + universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = process.communicate() # Find the scores in stdout of POLQA. - match = re.search(r'\bMOS-LQO:\s+([\d.]+)', out.decode('utf-8')) + match = re.search(r'\bMOS-LQO:\s+([\d.]+)', out) if process.returncode != 0 or not match: if process.returncode == 2: @@ -326,6 +310,7 @@ def main(): '--sample_rate_hz=%d' % analyzer.sample_rate_hz, '--test_case_prefix=%s' % analyzer.name, ] + args.extra_test_args), + universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) perf_results_file = None