Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to communicate two separate python processes?

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.

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... )

The solution should work on Linux and Windows.

like image 383
Robert Zaremba Avatar asked May 10 '11 15:05

Robert Zaremba


1 Answers

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.

like image 74
zeekay Avatar answered Oct 18 '22 03:10

zeekay