Stage 1 · Lesson 6 of 10
asyncio, threads and the GIL
A backend spends much of its time waiting on I/O (input and output, such as network calls). Python gives you two ways to do other work while waiting. The first is , where the operating system switches between tasks.
In standard , the (the GIL) lets only one thread run Python code at a time. But a thread that is waiting on I/O releases it, so threads still help with network calls. The second way is , which runs many (pausable functions) on one thread.
async def defines one, await hands control back while it waits, and asyncio.gather runs several at once. FastAPI builds on asyncio, and Django supports async views.
Common trapcalling blocking code, such as requests or time.sleep, inside an async function: it freezes the whole event loop, so every other request waits too.
A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Python basics in a sensible order: collections, functions, classes and modules
- CourseFreeCS50's Introduction to Programming with Python
Harvard University · Beginner
Free Harvard course with real problem sets, and it teaches unit tests early
Practise
Keep handy
Also worth your time
The DNS, TCP, TLS and HTTP steps behind every request your backend will handle