Python Communicating Sequential Processes — ELI5
Imagine a relay race. Each runner does their part and then hands the baton to the next person. Nobody starts running until they receive the baton. Nobody holds onto it — they pass it along.
Communicating Sequential Processes (CSP) works the same way. You have workers (processes) that each do one job. They pass data to each other through channels — like little tubes connecting them. A worker puts something into the channel and waits. The next worker takes it out and does their thing.
The magic part: both sides have to be ready at the same time. The sender waits until the receiver is ready to grab the data, and the receiver waits until the sender puts something in. It’s like a handshake — neither person can just toss a ball and walk away.
This is different from a mailbox where messages pile up. In CSP, communication is synchronized. That means you always know exactly where your data is at any moment.
In Python, you can do this with multiprocessing.Pipe, queue.Queue, or libraries built for this pattern. The Go programming language made CSP famous with goroutines and channels, but the idea works just as well in Python.
The one thing to remember: CSP is about workers that only talk through channels. No sharing data behind each other’s backs — just clean, synchronized hand-offs like a relay team.
See Also
- Python Actor Model Why treating each piece of your program like a person with their own mailbox makes concurrency way less scary.
- Python Aiocache Caching aiocache remembers expensive answers so your async Python app doesn't waste time asking the same question twice.
- Python Aiofiles Async Io aiofiles lets your async Python program read and write files without freezing — because normal file operations secretly block everything.
- Python Aiohttp Understand Aiohttp through an everyday analogy so Python behavior feels intuitive, not random.
- Python Anyio Portability AnyIO lets your async Python code work with any async library — write once, run on asyncio or Trio without changes.