[英]Python os.pipe vs multiprocessing.Pipe
Recently I'm studying parallel programming tools in Python. 最近我正在研究Python中的并行编程工具。 And here are two major differences between os.pipe and multiprocessing.Pipe.(despite the occasion they are used)
这是os.pipe和multiprocessing.Pipe之间的两个主要区别。(尽管它们被使用)
I want to know if my understanding is correct, and is there other difference? 我想知道我的理解是否正确,还有其他区别吗? Thank you.
谢谢。
I believe everything you've stated is correct. 我相信你所陈述的一切都是正确的。
On Linux, os.pipe
is just a Python interface for accessing traditional POSIX pipes. 在Linux上,
os.pipe
只是一个用于访问传统POSIX管道的Python接口。 On Windows, it's implemented using CreatePipe
. 在Windows上,它是使用
CreatePipe
实现的。 When you call it, you get two ordinary file descriptors back. 当你调用它时,你会得到两个普通的文件描述符。 It's unidirectional, and you just write bytes to it on one end that get buffered by the kernel until someone reads from the other side.
它是单向的,你只需在一端写入字节,由内核缓冲,直到有人从另一端读取。 It's fairly low-level, at least by Python standards.
这是相当低级的,至少是Python标准。
multiprocessing.Pipe
objects are much more high level interface, implemented using multiprocessing.Connection
objects. multiprocessing.Pipe
对象是更高级的接口,使用multiprocessing.Connection
实现。连接对象。 On Linux, these are actually built on top of POSIX sockets, rather than POSIX pipes. 在Linux上,这些实际上是建立在POSIX套接字之上,而不是POSIX管道。 On Windows, they're built using the
CreateNamedPipe
API. 在Windows上,它们是使用
CreateNamedPipe
API构建的。 As you noted, multiprocessing.Connection
objects can send/receive any picklable object, and will automatically handle the pickling/unpickling process, rather than just dealing with bytes. 如你所述,
multiprocessing.Connection
对象可以发送/接收任何可选对象,并自动处理pickle / unpickling进程,而不仅仅是处理字节。 They're capable of being both bidirectional and unidirectional. 它们既可以是双向的,也可以是单向的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.