Add Popen.start property.

R=dpranke@chromium.org
BUG=
TEST=


Review URL: http://codereview.chromium.org/8694006

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@112102 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
maruel@chromium.org
2011-11-30 01:55:22 +00:00
parent 7956a87b76
commit dd9837f9d9
2 changed files with 6 additions and 3 deletions

View File

@@ -139,6 +139,7 @@ class Popen(subprocess.Popen):
- Sets shell=True on windows by default. You can override this by forcing
shell parameter to a value.
- Adds support for VOID to not buffer when not needed.
- Adds self.start property.
Note: Popen() can throw OSError when cwd or args[0] doesn't exist. Translate
exceptions generated by cygwin when it fails trying to emulate fork().
@@ -180,6 +181,8 @@ class Popen(subprocess.Popen):
fix('stdout')
fix('stderr')
self.start = time.time()
try:
super(Popen, self).__init__(args, **kwargs)
except OSError, e:
@@ -200,7 +203,7 @@ class Popen(subprocess.Popen):
def communicate(args, timeout=None, **kwargs):
"""Wraps subprocess.Popen().communicate().
"""Wraps subprocess.Popen().communicate() and add timeout support.
Returns ((stdout, stderr), returncode).
@@ -232,14 +235,13 @@ def communicate(args, timeout=None, **kwargs):
# When the pipe fills up, it will deadlock this process. Using a real file
# works around that issue.
with tempfile.TemporaryFile() as buff:
start = time.time()
kwargs['stdout'] = buff
proc = Popen(args, **kwargs)
if stdin is not None:
proc.stdin.write(stdin)
while proc.returncode is None:
proc.poll()
if timeout and (time.time() - start) > timeout:
if timeout and (time.time() - proc.start) > timeout:
proc.kill()
proc.wait()
# It's -9 on linux and 1 on Windows. Standardize to TIMED_OUT.