本文整理汇总了Python中subprocess.Popen._mpipe_last方法的典型用法代码示例。如果您正苦于以下问题:Python Popen._mpipe_last方法的具体用法?Python Popen._mpipe_last怎么用?Python Popen._mpipe_last使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen._mpipe_last方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import _mpipe_last [as 别名]
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()
示例2: read
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import _mpipe_last [as 别名]
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
示例3: open
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import _mpipe_last [as 别名]
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