Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Unified Diff: subprocess2.py

Issue 8694006: Add Popen.start property. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/subprocess2_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: subprocess2.py
diff --git a/subprocess2.py b/subprocess2.py
index 3b48137988c3b2c529520940f0975d5a7ef7dbf3..8964aad7d495b9bcc2e10e1ffc12f6bb6b61b5d7 100644
--- a/subprocess2.py
+++ b/subprocess2.py
@@ -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.
« no previous file with comments | « no previous file | tests/subprocess2_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698