def shutdown_process(
    proc: subprocess.Popen,
    interrupt_timeout: Optional[int] = None,
    terminate_timeout: Optional[int] = None,
) -> int:
    """Shut down the process gracefully with SIGINT -> SIGTERM -> SIGKILL."""

    logger.info("sending interrupt signal to the process %s", proc.pid)
    proc.send_signal(SIGINT)

    logger.info("waiting for the process %s to finish", proc.pid)
    try:
        return proc.wait(interrupt_timeout)
    except subprocess.TimeoutExpired:
        logger.info(
            "timed out waiting, sending terminate signal to the process %s", proc.pid
        )
        proc.terminate()
        try:
            return proc.wait(terminate_timeout)
        except subprocess.TimeoutExpired:
            logger.info("timed out waiting, killing the process %s", proc.pid)
            proc.kill()
            return proc.wait()
Shut down the process gracefully with SIGINT -> SIGTERM -> SIGKILL.
src/datachain/catalog/catalog.py