kill and wait for subprocess before raising TimeoutExpired
This commit is contained in:
parent
d5e5433553
commit
33f0338eeb
|
@ -1066,18 +1066,23 @@ class Testdir(object):
|
||||||
)
|
)
|
||||||
timeout = kwargs.get("timeout")
|
timeout = kwargs.get("timeout")
|
||||||
|
|
||||||
|
def handle_timeout():
|
||||||
timeout_message = (
|
timeout_message = (
|
||||||
"{seconds} second timeout expired running:"
|
"{seconds} second timeout expired running:"
|
||||||
" {command}".format(seconds=timeout, command=cmdargs)
|
" {command}".format(seconds=timeout, command=cmdargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
popen.kill()
|
||||||
|
popen.wait()
|
||||||
|
raise self.TimeoutExpired(timeout_message)
|
||||||
|
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
ret = popen.wait()
|
ret = popen.wait()
|
||||||
elif six.PY3:
|
elif six.PY3:
|
||||||
try:
|
try:
|
||||||
ret = popen.wait(timeout)
|
ret = popen.wait(timeout)
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
raise self.TimeoutExpired(timeout_message)
|
handle_timeout()
|
||||||
else:
|
else:
|
||||||
end = time.time() + timeout
|
end = time.time() + timeout
|
||||||
|
|
||||||
|
@ -1088,7 +1093,7 @@ class Testdir(object):
|
||||||
|
|
||||||
remaining = end - time.time()
|
remaining = end - time.time()
|
||||||
if remaining <= 0:
|
if remaining <= 0:
|
||||||
raise self.TimeoutExpired(timeout_message)
|
handle_timeout()
|
||||||
|
|
||||||
time.sleep(remaining * 0.9)
|
time.sleep(remaining * 0.9)
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Reference in New Issue