Commit 22da3d35 authored by Robert Ma's avatar Robert Ma Committed by Commit Bot

[blinkpy] Block and wait for killed processes

In Executive.kill_process, drop WNOHANG from os.waitpid and use the
default blocking wait instead.

This makes sure we can reliably collect the defunct process, which fixes
a peculiar issue on macOS: when calling os.killpg on a defunct process
group, we get EACCES instead of failing silently, which makes a unit
test flaky on macOS.

Drive-by:
* Update the docstring to reflect the reality (we no longer ignore
  permission errors).

Bug: 1119341
Change-Id: I1efa79d8e610e67cede7d9492a82ba67abc8e0a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2459326Reviewed-by: default avatarDirk Pranke <dpranke@google.com>
Commit-Queue: Robert Ma <robertma@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815265}
parent 28b724f9
...@@ -110,7 +110,7 @@ class Executive(object): ...@@ -110,7 +110,7 @@ class Executive(object):
if kill_tree is True, the whole process group will be killed. if kill_tree is True, the whole process group will be killed.
Will fail silently if pid does not exist or insufficient permissions. Will fail silently if pid does not exist.
""" """
if sys.platform == 'win32': if sys.platform == 'win32':
# Workaround for race condition that occurs when the browser is # Workaround for race condition that occurs when the browser is
...@@ -136,7 +136,9 @@ class Executive(object): ...@@ -136,7 +136,9 @@ class Executive(object):
os.killpg(os.getpgid(pid), signal.SIGKILL) os.killpg(os.getpgid(pid), signal.SIGKILL)
else: else:
os.kill(pid, signal.SIGKILL) os.kill(pid, signal.SIGKILL)
os.waitpid(pid, os.WNOHANG) # At this point if no exception has been raised, the kill has
# succeeded, so we can safely use a blocking wait.
os.waitpid(pid, 0)
except OSError as error: except OSError as error:
if error.errno == errno.ESRCH: if error.errno == errno.ESRCH:
_log.debug("PID %s does not exist.", pid) _log.debug("PID %s does not exist.", pid)
......
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