Commit dd9837f9 authored by maruel@chromium.org's avatar maruel@chromium.org

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
parent 7956a87b
......@@ -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.
......
......@@ -142,6 +142,7 @@ class DefaultsTest(auto_stub.TestCase):
env['LANGUAGE'] = 'en_US.UTF-8'
expected['env'] = env
self.assertEquals(expected, results)
self.assertTrue(time.time() >= proc.start)
def test_check_output_defaults(self):
results = self._fake_communicate()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment