The answer to this one is simple (but not so easy to implement):
- Write a Python program to be executed on each machine.
- Write a (bash / shell) script that connects to your machines via SSH and starts the Python programs. You’ll need the IP addresses of all your machines.
- Use Python socket connections (based on the TCP protocol) to allow your Python programs to send each other TCP messages. You’ll need the IP addresses of all your machines again.
- Sending messages via TCP is a synchronous communication: your program blocks until it receives the response. If you want to make your program non-blocking, you can create separate threads that handle the sending and receiving of messages and execute “callback” functions in your main Python program. You can study multi-threading in Python.
This is how I would do it at least. I’m sure there are plenty of other ways to accomplish the same thing—but most of them will build upon TCP communication anyway.

While working as a researcher in distributed systems, Dr. Christian Mayer found his love for teaching computer science students.
To help students reach higher levels of Python success, he founded the programming education website Finxter.com that has taught exponential skills to millions of coders worldwide. He’s the author of the best-selling programming books Python One-Liners (NoStarch 2020), The Art of Clean Code (NoStarch 2022), and The Book of Dash (NoStarch 2022). Chris also coauthored the Coffee Break Python series of self-published books. He’s a computer science enthusiast, freelancer, and owner of one of the top 10 largest Python blogs worldwide.
His passions are writing, reading, and coding. But his greatest passion is to serve aspiring coders through Finxter and help them to boost their skills. You can join his free email academy here.