| 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.
|
|
|