def killProcessGroupHoldingPorts(portStart, portStop, retries = 5):
    toKillOrNone = pidAndProcessNameHoldingPorts(portStart, portStop)

    if toKillOrNone is None:
        return False

    pidToKill, processName = toKillOrNone

    try:
        pidGroupToKill = os.getpgid(pidToKill)

        logging.warn("Killing process group pgid=%s containing %s at pid=%s",
                pidGroupToKill,
                processName,
                pidToKill
                )

        os.killpg(pidGroupToKill, 9)
    except __HOLE__:
        logging.warn("Failed to kill process holding port: %s.\n%s",
                     toKillOrNone, traceback.format_exc()
                     )

    toKillOrNone2 = pidAndProcessNameHoldingPorts(portStart, portStop)

    if toKillOrNone2 is not None:
        logging.error(
            "Failed to free the port range %s-%s. It was held as %s, now as %s",
            portStart,
            portStop,
            toKillOrNone,
            toKillOrNone2
            )
        if retries < 1:
            raise UserWarning("Failed to clear the port")
        logging.info("Trying to kill process group holding port range %s-%s again", portStart, portStop)
        return killProcessGroupHoldingPorts(portStart, portStop, retries-1)

    return True
dataset/ETHPy150Open ufora/ufora/ufora/util/KillProcessHoldingPort.py/killProcessGroupHoldingPorts