buildfarm/utils/unix_util.py
author Chris AtLee <catlee@mozilla.com>
Mon, 01 Apr 2019 17:26:27 +0000
changeset 8471 a41a482b78763e8159c9b3407a2e7dd37ce8d583
parent 8458 4f4834b9c6f75e5c0ad8dbb98f19613993cd6363
permissions -rw-r--r--
Bug 1531165: Remove jar signing support, and signscript imports r=aki Differential Revision: https://phabricator.services.mozilla.com/D25632

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]