Python Channels: CSP Concurrency & Pipelines
Go follows Hoare Communicating Sequential Processes (CSP). Channels provide typed synchronization conduits between goroutines. Master unbuffered vs buffered channels, channel closing, and pipeline streaming.
"An unbuffered channel is handing a baton in a relay race—both runners must meet at the exact same instant. A buffered channel is a mail drop box with fixed slots."
Deep Dive: How It Works
CSP Philosophy: "Do not communicate by sharing memory; instead, share memory by communicating."
Unbuffered Channels: Synchronous rendezvous where send blocks until receiver is ready and vice versa.
Buffered Channels: Non-blocking until internal buffer capacity is full.
Range over Channels: for v := range ch drains values until sender calls close(ch).
Syntax Blueprint
ch := make(chan int, 2) ch <- 42 val := <-ch close(ch)
Create buffered/unbuffered channels with make, send with <-, receive with <-, and close with close().
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Sending to a closed channel: close(ch); ch <- 1.Why it happens: Sending to or closing a closed channel triggers an immediate runtime panic.
How to fix: Ensure only the producer closes the channel once.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Sum Numbers through a Channel
Write a function sumWorker(nums []int, out chan<- int) that calculates the sum of a slice and sends it to out.
In main(), launch sumWorker on slice [10, 20, 30] in a goroutine.
Receive the sum from the channel and print "Total: %d".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.