如何通信两个单独的python进程? [英] how to communicate two separate python processes?

查看:445
本文介绍了如何通信两个单独的python进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个python程序,我想与他们交流.
它们都是系统服务,并且都不是由父进程派生的.

I have two python programs and I want to communicate them.
Both of them are system services and none of them is forked by parent process.

有没有不使用套接字的方法吗?
(例如,创建一些Queue->序列化->由其他进程反序列化并执行通信;或在要执行通信的文件上写入进程ID,然后创建获取进程ID并向该进程发送一些消息的魔术结构... )

Is there any way to do this without using sockets?
(eg by crating some Queue -> serialize it -> deserialize by other process and perform communication; or write on file process id to which perform communication, and then create magic structure which gets process id and send some messages to this process... )

该解决方案应可在Linux和Windows上运行.

The solution should work on Linux and Windows.

推荐答案

您最好的选择是 ZeroMQ ,是专为IPC设计的,并且使用IPC的速度非常快(还支持TCP/多播消息传递). Python绑定非常好,并且易于使用.此处对Python的ZeroMQ进行了很好的介绍: http://nichol.as/zeromq-an-introduction .如果您打算将其扩展到多台机器上,那么AMQP(这是一个消息队列协议)将是一个不错的选择,有很多很棒的库可用于AMQP for python.我真的很喜欢 kombu 扭曲,它为您提供了相当疯狂的通信选项,并且提供了一个不错的事件循环启动.

Your best bet is ZeroMQ, which is designed for, and extremely fast at IPC (also supports TCP/multicast messaging as well). The Python bindings are really nice, and easy to work with. There is a nice introduction to ZeroMQ with Python here: http://nichol.as/zeromq-an-introduction. If you were planning to expand this across multiple machines, AMQP (which is a message queue protocol) would be a good to look at, there are a lot of great libraries for working with AMQP for python. I really like kombu and celery. You could also think about twisted, which gives you a fairly insane number of options for communication, and a nice event loop to boot.

这篇关于如何通信两个单独的python进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆