def kindly_end()

in dcrpm/util.py [0:0]


def kindly_end(proc, timeout=END_TIMEOUT):
    # type: (subprocess.Popen, int) -> int
    """
    Tries to nicely end process `proc`, first by sending SIGTERM and then, if it
    is still running, SIGKILL.
    """
    rc = 1  # type: t.Optional[int]
    try:
        _logger.info("Sending SIGTERM to %d", proc.pid)
        proc.terminate()
        rc = call_with_timeout(proc.wait, timeout)
    except TimeoutExpired:
        _logger.warning("Could not SIGTERM %d, sending SIGKILL", proc.pid)
        try:
            proc.kill()
            rc = call_with_timeout(proc.wait, timeout)
        except TimeoutExpired:
            _logger.error("Could not SIGKILL %d, good luck", proc.pid)

    return rc if rc else 1