Ejemplo n.º 1
0
def write(proc : Popen, data):
    """Write message to the process."""
    if proc._mpipe_last == "write":
        raise RuntimeError("Consecutive write not allowed in rpc_mode")
    proc._mpipe_last = "write"
    pack = umsgpack.dumps(data)
    size = bytes(ctypes.c_size_t(len(pack)))
    proc.stdin.write(size)
    proc.stdin.write(pack)
    proc.stdin.flush()
Ejemplo n.º 2
0
def write(proc: Popen, data):
    """Write message to the process."""
    if proc._mpipe_last == "write":
        raise RuntimeError("Consecutive write not allowed in rpc_mode")
    proc._mpipe_last = "write"
    pack = umsgpack.dumps(data)
    size = bytes(ctypes.c_size_t(len(pack)))
    proc.stdin.write(size)
    proc.stdin.write(pack)
    proc.stdin.flush()
Ejemplo n.º 3
0
def read(proc: Popen):
    """Read message from the process, returns None on failure."""
    if proc._mpipe_last == "read":
        raise RuntimeError("Consecutive read not allowed in rpc_mode")
    proc._mpipe_last = "read"
    size = proc.stdout.read(ctypes.sizeof(ctypes.c_size_t))
    size = int.from_bytes(size, sys.byteorder)
    pack = proc.stdout.read(size)
    try:
        return umsgpack.loads(pack)
    except umsgpack.InsufficientDataException as e:
        if proc.poll() != 0:
            raise RuntimeError("The process returned %d." % proc.returncode) from e
        else:
            raise
Ejemplo n.º 4
0
def read(proc : Popen):
    """Read message from the process, returns None on failure."""
    if proc._mpipe_last == "read":
        raise RuntimeError("Consecutive read not allowed in rpc_mode")
    proc._mpipe_last = "read"
    size = proc.stdout.read(ctypes.sizeof(ctypes.c_size_t))
    size = int.from_bytes(size,  sys.byteorder)
    pack = proc.stdout.read(size)
    try:
        return umsgpack.loads(pack)
    except umsgpack.InsufficientDataException as e:
        if proc.poll() != 0:
            raise RuntimeError(
                "The process returned %d." % proc.returncode
            ) from e
        else:
            raise
Ejemplo n.º 5
0
def open(args : list) -> Popen:
    """Open a subprocess for sending message-pack messages."""
    if os.environ.get("MPP_RR") == "True":
        proc = Popen(["rr"] + args, stdin=PIPE, stdout=PIPE)
    elif mc:
        proc = Popen(
            [
                "valgrind",
                "--tool=memcheck",
                "--leak-check=full",
                "--show-leak-kinds=all",
                "--errors-for-leak-kinds=all",
                "--error-exitcode=1",
                "--suppressions=%s" % mc,
            ] + args,
            stdin=PIPE,
            stdout=PIPE,
            preexec_fn=os.setsid
        )
    else:
        proc = Popen(args, stdin=PIPE, stdout=PIPE, preexec_fn=os.setsid)
    proc._mpipe_last = None
    return proc
Ejemplo n.º 6
0
def open(args: list) -> Popen:
    """Open a subprocess for sending message-pack messages."""
    if os.environ.get("MPP_RR") == "True":
        proc = Popen(["rr"] + args, stdin=PIPE, stdout=PIPE)
    elif mc:
        proc = Popen(
            [
                "valgrind",
                "--tool=memcheck",
                "--leak-check=full",
                "--show-leak-kinds=all",
                "--errors-for-leak-kinds=all",
                "--error-exitcode=1",
                "--suppressions=%s" % mc,
            ]
            + args,
            stdin=PIPE,
            stdout=PIPE,
            preexec_fn=os.setsid,
        )
    else:
        proc = Popen(args, stdin=PIPE, stdout=PIPE, preexec_fn=os.setsid)
    proc._mpipe_last = None
    return proc