user1012037
user1012037

Reputation: 501

Python interprocess communication advice

I have 2 python servers running independently of one another but sharing the same database. They need to communicate with each other about when certain changes have been made to the database so the other server (if running) can reload cached data.

What would be my best options for communicating between two such programs?

I've thought of using sockets but it seems like a lot of work. Either one program will be polling connect whenever the other is off, or they both need to have server/client capabilities. I looked into named pipes but didn't see any easy portable solution (needs to run on windows and unix).

Upvotes: 2

Views: 1920

Answers (3)

shaunc
shaunc

Reputation: 5611

I agree that sockets are usually too low-level. If you investigate "RabbitMQ", you should also investigate celery. It can use RabbitMQ as a back-end, but it can also use the database, and it neatly encapsulates the messaging mechanism. It is also integrated with django and gevent.

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 386332

You could have each one implement a simple XMLRPC server. Each one can then execute code in the other, such as telling the other one it needs to update.

Upvotes: 5

Raymond Hettinger
Raymond Hettinger

Reputation: 226634

The easiest way is to use the database itself as a means of communication. Add a table for logging updates. Then, either machine can periodically query to see if the underlying data has been changed.

Another easy form of communication is email using the smtplib module. Our buildbots and version control repository use this form of communication.

If you want something with a little more "industrial" strength, consider using RabbitMQ or somesuch for messaging between servers.

Upvotes: 3

Related Questions