The best resource I’ve found is David Beazley’s Python Concurrency From the Ground Up: LIVE!. Not only does he do live coding without mistakes, bu

Python Concurrency: Threads, Processes, and asyncio Explained

submited by
Style Pass
2025-01-07 21:00:09

The best resource I’ve found is David Beazley’s Python Concurrency From the Ground Up: LIVE!. Not only does he do live coding without mistakes, but he explains it very intuitively. This post is a summary of his talk, plus a section on asyncio (wasn’t released at the time).

For the first item, we are using the Fibonacci sequence . It’s familiar and it perfectly shows our concurrency challenges. When you’re computing fib(50), you’ll appreciate why it matters.

Next, Dave uses socket programming to create a web server. This is helpful for seeing the effect of multiple calls to a CPU-bound task.

Now, you can input any number and the server will give you the result if fib(n). But as we mentioned earlier, it can only handle one connection at a time. You can test this by running telnet localhost 25000 in another terminal, type any number, and see that it doesn’t return a result.

This script, perf1.py, simulates a long running request (running fib(30)). If we run this python perf1.py in one terminal, we might see something like:

Leave a Comment