Python的Multiprocessing之进程通信

Process communication of Python#39;s Multiprocessing(Python的Multiprocessing之进程通信)
本文介绍了Python的Multiprocessing之进程通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我了解了 Python 多进程的 Pipes/Queues/Shared ctypes Objects/Managers,我想将它们与 Linux 的匿名管道、命名管道、共享内存、套接字等进行比较.我现在有以下问题

I've learned about Python multiprocess's Pipes/Queues/Shared ctypes Objects/Managers, and I want to compare them with Linux's anonymous pipes, named pipes, shared memory, socket, and so on. I now have the following questions

  • Python 多处理的管道和队列模块是基于匿名管道的.是否提供命名管道?

  • The pipes and queue modules of Python's multiprocessing are based on anonymous pipes. Does it provide named pipes?

Python multiprocessing.sharedctypes 是否支持独立进程沟通?我认为它只支持父子进程或兄弟进程通信.

Does Python multiprocessing.sharedctypes support independent process communication? I think it only supports father and child process or brotherly process communication.

其中哪些仅用于亲子鉴定过程中或兄弟情谊,可以在独立进程之间进行通信还是不同的主机?

Which of them are only used in the process of paternity or brotherhood, which can be communicated between independent processes or different hosts?

它们各自的特点是什么,应该如何选择?

What are their respective characteristics, how should I choose them?

提前致谢.

推荐答案

您的问题相当广泛,大部分答案都可以在 multiprocessing 模块文档中找到.

Your question is quite broad and most of the answers can be found in the multiprocessing module documentation.

下面是一个简短的回答.

Here follows a somewhat short answer.

  1. 多处理侦听器和客户端 允许选择命名管道作为传输介质.
  2. 来自 文档:

  1. The multiprocessing Listeners and Clients allow to choose named pipes as transport medium.
  2. From the documentation:

multiprocessing.sharedctypes 模块提供了从共享内存中分配 ctypes 对象的函数,这些对象可以被子进程继承.

The multiprocessing.sharedctypes module provides functions for allocating ctypes objects from shared memory which can be inherited by child processes.

您不能跨没有父/子关系的进程使用 multiprocessing.sharedctypes 功能.

You cannot use multiprocessing.sharedctypes functionalities across processes which don't have parent/child relationship.

Python multiprocessing 模块最初是通过 threading API 实现的.到那时,它支持的功能有所增长,但核心思想保持不变.multiprocessing 模块旨在处理 Python 进程系列.对于任何其他用途,subprocess 模块是更好的选择.

Python multiprocessing module was initially implemented over the threading APIs. By the time, it grew in features it supports but the core idea remains the same. The multiprocessing module is intended to deal with Python process families. For any other use, the subprocess module is a better option.

对于跨多个主机分配任务和作业,有更好的解决方案来抽象低级基础架构.您可以查看 Python 项目,例如 Celery 或 Luigi 或更复杂的基础架构,例如 Apache Mesos.

For distribution of tasks and jobs across multiple hosts, there are far better solutions abstracting the low level infrastructure. You can take a look at Python projects such as Celery or Luigi or more complex infrastructures such as Apache Mesos.

这篇关于Python的Multiprocessing之进程通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multiprocessing on Windows breaks(Windows 上的多处理中断)
How to use a generator as an iterable with Multiprocessing map function(如何将生成器用作具有多处理映射功能的可迭代对象)
read multiple files using multiprocessing(使用多处理读取多个文件)
Why does importing module in #39;__main__#39; not allow multiprocessig to use module?(为什么在__main__中导入模块不允许multiprocessig使用模块?)
Trouble using a lock with multiprocessing.Pool: pickling error(使用带有 multiprocessing.Pool 的锁时遇到问题:酸洗错误)
Python sharing a dictionary between parallel processes(Python 在并行进程之间共享字典)