buildfarm/utils/unix_util.py
author Nick Thomas <nthomas@mozilla.com>
Tue, 25 Sep 2018 14:34:08 +1200
changeset 8458 4f4834b9c6f7
permissions -rw-r--r--
nobug - restore unix_util.py for update verify r=bustate

import signal
import os
import time


def kill(pid):
    """Kill process pid with progressively more agressive signals."""
    siglist = [signal.SIGINT, signal.SIGTERM]
    while True:
        if siglist:
            sig = siglist.pop(0)
        else:
            sig = signal.SIGKILL
        os.kill(pid, sig)
        time.sleep(5)
        rc = os.waitpid(pid, os.WNOHANG)
        try:
            os.kill(pid, 0)
        except OSError:
            return rc[1]