2

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

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.