Commit 7167159a authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

utils.KillProcess: Use waitpid() to wait for child processes

Sometimes the proc filesystem doesn't reflect the current status of
a process. By calling waitpid(), we make sure to get the current
information, at least for child processes. The timeout is still
kept for child processes to make sure the proc filesystem is updated.

Reviewed-by: iustinp
parent 26de0cf1
......@@ -1469,10 +1469,24 @@ def KillProcess(pid, signal_=signal.SIGTERM, timeout=30,
_helper(pid, signal_, waitpid)
if timeout <= 0:
return
# Wait up to $timeout seconds
end = time.time() + timeout
wait = 0.01
while time.time() < end and IsProcessAlive(pid):
time.sleep(0.1)
try:
(result_pid, _) = os.waitpid(pid, os.WNOHANG)
if result_pid > 0:
break
except OSError:
pass
time.sleep(wait)
# Make wait time longer for next try
if wait < 0.1:
wait *= 1.5
if IsProcessAlive(pid):
# Kill process if it's still alive
_helper(pid, signal.SIGKILL, waitpid)
......
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