Generators, Coroutines, and Nanoservices
summary
Explains how Python generator functions become in-process nanoservices using yield/send as a request/response protocol, with examples: an infinite fib generator, chunked file readers, a vowel scanner, an MD5 hashing service using hashlib, and a weather-forecast coroutine that fetches JSON from the WMO URL. Shows priming (next or decorator), the walrus operator for cleaner loops, delegation via yield from, throw/close semantics, and why this pattern works but can be hard to debug.
AI-written summary · about
chapters (20)
- 0:00Introduction
- 1:10About the speaker
- 3:59Generators vs functions
- 6:04Iterator protocol
- 8:29Manual generator iteration
- 10:38Fibonacci generator
- 12:24Reading files in chunks
- 13:27Yielding vowels from a file
- 14:51Coroutines with send
- 18:24Walrus operator in coroutines
- 20:06Coroutines as nano services
- 21:10MD5 hash service
- 22:34Weather forecast service
- 24:18Database query engine
- 26:22Closing and throwing exceptions
- 27:24Combining services
- 29:31Yield from for coroutines
- 30:13Async IO and coroutines
- 30:56When to use coroutines
- 31:36Q&A
