简体   繁体   English

多处理程序支持命名管道(FIFO)吗?

[英]Does multiprocessing support named pipes (FIFO)?

多处理的管道队列基于匿名管道,Python的multiprocessing是否提供命名管道(FIFO)?

There's no built-in support for a cross-platform abstraction of named pipes in multiprocessing . multiprocessing对命名管道的跨平台抽象的内置支持。

If you only care about Unix, or only about Windows, you can of course create named pipes manually. 如果只关心Unix,或者只关心Windows,那么当然可以手动创建命名管道。 For Unix, mkfifo is in the stdlib. 对于Unix, mkfifo位于stdlib中。 For Windows, you have to use ctypes or cffi , or a third-party library like win32api to call CreateFile with the right arguments. 对于Windows,您必须使用ctypescffi或诸如win32api类的第三方库来使用正确的参数调用CreateFile

Trying to abstract over the semantic differences between the two is pretty painful, which is probably why the stdlib doesn't attempt to do so. 试图抽象两者之间的语义差异是很痛苦的,这可能就是为什么stdlib不尝试这样做的原因。 (For example, Windows named pipes are volatile; posix named pipes are permanent.) (例如,Windows命名管道是易失的; posix命名管道是永久的。)

Here's a trivial Unix example: 这是一个简单的Unix示例:

import multiprocessing
import os

def child():
    with open('mypipe', 'rb') as p:
        print(p.read())

def main():
    try:
        os.mkfifo('mypipe')
    except FileExistsError:
        pass
    multiprocessing.Process(target=child).start()
    with open('mypipe', 'wb') as p:
        p.write(b'hi')
    os.remove('mypipe')

if __name__ == '__main__':
    main()

class multiprocessing.connection.Listener([address[, family[, backlog[, authkey]]]]) class multiprocessing.connection.Listener([地址[,家庭[,待办事项[,authkey]]]])

A wrapper for a bound socket or Windows named pipe which is 'listening' for connections.address is the address to be used by the bound socket or named pipe of the listener object. 绑定套接字或Windows命名管道的包装程序,正在“监听”连接。address是侦听器对象的绑定套接字或命名管道要使用的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM