Use the same logic as Python3.5 for handling timeouts #1807

This commit is contained in:
Thomas Nagy 2016-08-28 11:03:04 +02:00
parent 1fb3bfee6a
commit 8dba949014
No known key found for this signature in database
GPG Key ID: 49B4C67C05277AAA
3 changed files with 17 additions and 12 deletions

View File

@ -331,14 +331,15 @@ class Context(ctx):
if Logs.verbose and not kw['shell'] and not Utils.check_exe(cmd[0]):
raise Errors.WafError('Program %s not found!' % cmd[0])
wargs = {}
cargs = {}
if 'timeout' in kw:
if kw['timeout'] is not None:
wargs['timeout'] = kw['timeout']
if kw['shell']:
Logs.warn('Shell commands cannot timeout %r', cmd)
del kw['timeout']
if 'input' in kw:
if kw['input']:
wargs['input'] = kw['input']
cargs['input'] = kw['input']
kw['stdin'] = subprocess.PIPE
del kw['input']
@ -347,7 +348,7 @@ class Context(ctx):
kw['cwd'] = kw['cwd'].abspath()
try:
ret, out, err = Utils.run_process(cmd, kw, wargs)
ret, out, err = Utils.run_process(cmd, kw, cargs)
except Exception as e:
raise Errors.WafError('Execution failure: %s' % str(e), ex=e)
@ -415,14 +416,15 @@ class Context(ctx):
if quiet is None:
self.to_log(cmd)
wargs = {}
cargs = {}
if 'timeout' in kw:
if kw['timeout'] is not None:
wargs['timeout'] = kw['timeout']
if kw['shell']:
Logs.warn('Shell commands cannot timeout %r', cmd)
del kw['timeout']
if 'input' in kw:
if kw['input']:
wargs['input'] = kw['input']
cargs['input'] = kw['input']
kw['stdin'] = subprocess.PIPE
del kw['input']
@ -431,7 +433,7 @@ class Context(ctx):
kw['cwd'] = kw['cwd'].abspath()
try:
ret, out, err = Utils.run_process(cmd, kw, wargs)
ret, out, err = Utils.run_process(cmd, kw, cargs)
except Exception as e:
raise Errors.WafError('Execution failure: %s' % str(e), ex=e)

View File

@ -866,15 +866,17 @@ def run_regular_process(cmd, kwargs, cargs={}):
out, err = proc.communicate(**cargs)
except TimeoutExpired:
proc.kill()
out, err = proc.communicate(**cargs)
out, err = proc.communicate()
raise TimeoutExpired(proc.args, timeout=cargs['timeout'], output=out, stderr=err)
status = proc.returncode
else:
out, err = (None, None)
try:
status = proc.wait(**cargs)
except TimeoutExpired:
except TimeoutExpired as e:
proc.kill()
status = proc.wait(**cargs)
proc.wait()
raise e
return status, out, err
def run_process(cmd, kwargs, cargs={}):

View File

@ -35,7 +35,8 @@ def run():
out, err = proc.communicate(**cargs)
except TimeoutExpired:
proc.kill()
out, err = proc.communicate(**cargs)
out, err = proc.communicate()
raise TimeoutExpired(proc.args, timeout=cargs['timeout'], output=out, stderr=err)
ret = proc.returncode
except Exception as e:
exc_type, exc_value, tb = sys.exc_info()