def _run_with_timeout(p, timeout, kill_signal, kill_tree=True):
    """Return False if we timed out, True else."""
    def alarm_handler(signum, frame):
        raise _Alarm

    if timeout == 0:       # this is mostly useful for testing
        return False

    signal.signal(signal.SIGALRM, alarm_handler)
    signal.alarm(timeout)

    try:
        p.communicate()
        signal.alarm(0)
        return True
    except _Alarm:
        pids = [p.pid]
        if kill_tree:
            pids.extend(_get_process_children(p.pid))
        for pid in pids:
            # process might have died before getting to this line
            # so wrap to avoid OSError: no such process
            try:
                os.kill(pid, kill_signal)
            except __HOLE__:
                pass
        return False
dataset/ETHPy150Open Khan/alertlib/timeout.py/_run_with_timeout