- Phase: 10. Concurrency & Internals
- Duration: 2.5 hours
- Write async code using async/await syntax
- Understand the event loop and how it drives coroutines
- Create and manage tasks with asyncio.create_task and asyncio.gather
- Recognize awaitable objects (coroutines, tasks, futures)
- Perform async I/O with aiohttp
- Decide when async helps (I/O-bound vs CPU-bound)
- async/await syntax
- Event loop
- Coroutines
- Tasks: asyncio.create_task, asyncio.gather
- Awaitable objects
- asyncio.sleep for cooperative yielding
- Running async code: asyncio.run
- aiohttp for async HTTP
- I/O-bound vs CPU-bound decisions
Modules 000-092.
import asyncio
from typing import List
async def fetch(url: str) -> str:
await asyncio.sleep(0.1)
return f"Data from {url}"
async def main() -> None:
tasks: List[asyncio.Task] = [
asyncio.create_task(fetch(f"https://api.example.com/{i}"))
for i in range(5)
]
results: List[str] = await asyncio.gather(*tasks)
print(results)
asyncio.run(main())- Python asyncio documentation
- aiohttp documentation
- "Using asyncio" by Caleb Hattingh (O'Reilly)
Module 094: Memory Management & Garbage Collection in CPython