在进程之间进行通信时,通过管道排队的优点是什么?
问题描述:
使用2 管道上排队 a> 在进程之间进行通信?
What would be the advantage(s) (if any) of using 2 Queues over a Pipe to communicate between processes?
我打算使用multiprocessing
python模块.
I am planning on using the multiprocessing
python module.
答
最大的好处就是队列是进程和线程安全的.管道不是:如果两个不同的进程试图读取或写入管道的同一端,则会发生不良情况.队列的抽象级别也比管道更高,这在您的特定情况下可能是优势,也可能不是优势.
The big win is that queues are process- and thread- safe. Pipes are not: if two different processes try to read from or write to the same end of a pipe, bad things happen. Queues are also at a somewhat higher level of abstraction than pipes, which may or may not be an advantage in your specific case.