INNER CODE UNIT · Python

execute

oneclickvirt/ecs · agent/server.py:60

def execute(argv, timeout=30, cwd=None, parse_json=True):
    """Bound output, kill process groups on timeout, never invoke a shell."""
    if not argv or not shutil.which(argv[0]):
        raise ValueError("Required local command is missing: " + (argv[0] if argv else ""))
    with tempfile.TemporaryFile() as out, tempfile.TemporaryFile() as err:
        proc = subprocess.Popen(argv, stdin=subprocess.DEVNULL, stdout=out, stderr=err,
                                start_new_session=os.name != "nt", cwd=cwd)
        try:
            proc.wait(timeout=timeout)
        except subprocess.TimeoutExpired:
            if os.name != "nt":
                os.killpg(proc.pid, signal.SIGKILL)
            else:
                subprocess.run(["taskkill", "/PID", str(proc.pid), "/T", "/F"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=False)
                if proc.poll() is None:
                    proc.kill()
            proc.wait()
            raise ValueError("Command exceeded its time limit; no result is claimed")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…