summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcraigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-10 00:38:06 +0000
committercraigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-10 00:38:06 +0000
commit81fdd5c14a8e462fa157407767e024ccd8fb604a (patch)
tree1c353835b45779288bd827126e96ebcf57349400
parentffad3ddb76d1b3e6effd490dcc45453687d45bf2 (diff)
downloadchromium_src-81fdd5c14a8e462fa157407767e024ccd8fb604a.zip
chromium_src-81fdd5c14a8e462fa157407767e024ccd8fb604a.tar.gz
chromium_src-81fdd5c14a8e462fa157407767e024ccd8fb604a.tar.bz2
[Android] Switch all subprocess.Popen calls to use a temporary file and other Python bug workarounds.
BUG=224382 TEST=Ran tests. Review URL: https://codereview.chromium.org/13861026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193273 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--build/android/pylib/android_commands.py9
-rw-r--r--build/android/pylib/cmd_helper.py24
-rwxr-xr-xbuild/android/pylib/utils/findbugs.py6
-rw-r--r--build/android/pylib/utils/flakiness_dashboard_results_uploader.py10
4 files changed, 31 insertions, 18 deletions
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index e565ec8..f370efe 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -204,6 +204,7 @@ class AndroidCommands(object):
self._device = device
self._logcat = None
self.logcat_process = None
+ self._logcat_tmpoutfile = None
self._pushed_files = []
self._device_utc_offset = self.RunShellCommand('date +%z')[0]
self._md5sum_path = ''
@@ -955,8 +956,9 @@ class AndroidCommands(object):
self._adb.SendCommand('logcat -c')
logcat_command = 'adb %s logcat -v threadtime %s' % (self._adb._target_arg,
' '.join(filters))
+ self._logcat_tmpoutfile = tempfile.TemporaryFile(bufsize=0)
self.logcat_process = subprocess.Popen(logcat_command, shell=True,
- stdout=subprocess.PIPE)
+ stdout=self._logcat_tmpoutfile)
def StopRecordingLogcat(self):
"""Stops an existing logcat recording subprocess and returns output.
@@ -972,8 +974,11 @@ class AndroidCommands(object):
# Otherwise the communicate may return incomplete output due to pipe break.
if self.logcat_process.poll() is None:
self.logcat_process.kill()
- (output, _) = self.logcat_process.communicate()
+ self.logcat_process.wait()
self.logcat_process = None
+ self._logcat_tmpoutfile.seek(0)
+ output = self._logcat_tmpoutfile.read()
+ self._logcat_tmpoutfile.close()
return output
def SearchLogcatRecord(self, record, message, thread_id=None, proc_id=None,
diff --git a/build/android/pylib/cmd_helper.py b/build/android/pylib/cmd_helper.py
index 6dcc911..e910241 100644
--- a/build/android/pylib/cmd_helper.py
+++ b/build/android/pylib/cmd_helper.py
@@ -6,11 +6,20 @@
import os
import logging
+import signal
import subprocess
+import tempfile
import constants
+def _Call(args, stdout=None, stderr=None, shell=None, cwd=None):
+ return subprocess.call(
+ args=args, cwd=cwd, stdout=stdout, stderr=stderr,
+ shell=shell, close_fds=True,
+ preexec_fn=lambda: signal.signal(signal.SIGPIPE, signal.SIG_DFL))
+
+
def RunCmd(args, cwd=None):
"""Opens a subprocess to execute a program and returns its return value.
@@ -24,7 +33,7 @@ def RunCmd(args, cwd=None):
Return code from the command execution.
"""
logging.info(str(args) + ' ' + (cwd or ''))
- return subprocess.call(args, cwd=cwd)
+ return _Call(args, cwd=cwd)
def GetCmdOutput(args, cwd=None, shell=False):
@@ -59,12 +68,17 @@ def GetCmdStatusAndOutput(args, cwd=None, shell=False):
The tuple (exit code, output).
"""
logging.info(str(args) + ' ' + (cwd or ''))
- p = subprocess.Popen(args=args, cwd=cwd, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE, shell=shell)
- stdout, stderr = p.communicate()
- exit_code = p.returncode
+ tmpout = tempfile.TemporaryFile(bufsize=0)
+ tmperr = tempfile.TemporaryFile(bufsize=0)
+ exit_code = _Call(args, cwd=cwd, stdout=tmpout, stderr=tmperr, shell=shell)
+ tmperr.seek(0)
+ stderr = tmperr.read()
+ tmperr.close()
if stderr:
logging.critical(stderr)
+ tmpout.seek(0)
+ stdout = tmpout.read()
+ tmpout.close()
logging.info(stdout[:4096]) # Truncate output longer than 4k.
return (exit_code, stdout)
diff --git a/build/android/pylib/utils/findbugs.py b/build/android/pylib/utils/findbugs.py
index 3ad2c5a..995801a 100755
--- a/build/android/pylib/utils/findbugs.py
+++ b/build/android/pylib/utils/findbugs.py
@@ -11,6 +11,7 @@ import shlex
import subprocess
import sys
+from pylib import cmd_helper
from pylib import constants
@@ -73,10 +74,7 @@ def _GetChromeClasses(release_version):
version = 'Release'
path = os.path.join(constants.CHROME_DIR, 'out', version)
cmd = 'find %s -name "*.class"' % path
- proc = subprocess.Popen(shlex.split(cmd),
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = proc.communicate()
-
+ out = cmd_helper.GetCmdOutput(shlex.split(cmd))
if not out:
print 'No classes found in %s' % path
return out
diff --git a/build/android/pylib/utils/flakiness_dashboard_results_uploader.py b/build/android/pylib/utils/flakiness_dashboard_results_uploader.py
index 03f3740..291308e 100644
--- a/build/android/pylib/utils/flakiness_dashboard_results_uploader.py
+++ b/build/android/pylib/utils/flakiness_dashboard_results_uploader.py
@@ -30,6 +30,7 @@ from webkitpy.common.system import executive, filesystem
from webkitpy.layout_tests.layout_package import json_results_generator
#TODO(craigdh): pylib/utils/ should not depend on pylib/.
+from pylib import cmd_helper
from pylib import constants
@@ -97,9 +98,7 @@ class JSONResultsGenerator(json_results_generator.JSONResultsGeneratorBase):
in_directory: The directory where git is to be run.
"""
command_line = ['git', 'log', '-1', '--pretty=format:%H']
- output = subprocess.Popen(command_line,
- cwd=in_directory,
- stdout=subprocess.PIPE).communicate()[0]
+ output = cmd_helper.GetCmdOutput(command_line, cwd=in_directory)
return output[0:40]
in_directory = os.path.join(constants.CHROME_DIR, in_directory)
@@ -110,10 +109,7 @@ class JSONResultsGenerator(json_results_generator.JSONResultsGeneratorBase):
else:
return ''
- # Note: Not thread safe: http://bugs.python.org/issue2320
- output = subprocess.Popen(['svn', 'info', '--xml'],
- cwd=in_directory,
- stdout=subprocess.PIPE).communicate()[0]
+ output = cmd_helper.GetCmdOutput(['svn', 'info', '--xml'], cwd=in_directory)
try:
dom = xml.dom.minidom.parseString(output)
return dom.getElementsByTagName('entry')[0].getAttribute('revision')