[英]use multiprocessing as local IPC
I'm considering using Python's multiprocessing package for messaging between local python programs. 我正在考虑使用Python的多处理程序包在本地python程序之间进行消息传递。
This seems like the right way to go IF: 这似乎是去IF的正确方法:
Is it possible in case the python processes were run independently by the user, ie one did not spawn the other? 如果python进程是由用户独立运行的,例如一个进程没有产生另一个进程,是否可能?
How? 怎么样?
The docs seem to give examples only of cases where one spawns the other. 该文档似乎仅提供其中一个产生另一个的示例。
The programs will always run locally on the same machine (and same OS instance)
程序将始终在同一台计算机(和同一OS实例)上本地运行
Multiprocessing allows to have remote concurrency . 多处理允许具有远程并发 。
The programs' implementation will remain in Python
程序的实现将保留在Python中
Yes and no. 是的,没有。 You could wrap another command in a python function.
您可以将另一个命令包装在python函数中。 This will work, for example:
这将起作用,例如:
from multiprocessing import Process
import subprocess
def f(name):
subprocess.call(["ls", "-l"])
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
Speed is important
速度很重要
That depends from a number of factors: 这取决于许多因素:
Is it possible in case the python processes were run independently by the user, ie one did not spawn the other?
如果python进程是由用户独立运行的,例如一个进程没有产生另一个进程,是否可能?
I'm not an expert on the subject, but I implemented something similar once by using files to exchange data [basically one process' output file was monitored as input source by the other, and vice-versa]. 我不是该主题的专家,但是我曾经通过使用文件交换数据来实现了类似的操作[基本上,一个进程的输出文件被另一个进程监视为输入源,反之亦然]。
HTH! HTH!
请参阅侦听器和客户端
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.