Generators, coroutines and nanoservices
summary
Explains Python generator features beyond simple iterators—specifically generator.send and yield from—and presents coroutines as useful in-process "nanoservices" for structuring code. Describes when treating coroutines like nanoservices makes them appropriate or inappropriate for solving problems.
AI-written summary · about
chapters (30)
- 0:00Intro
- 0:29I teach Python!
- 1:33The dumbest function in the world
- 2:31Bytecode from our function
- 3:04Resume?
- 4:01"yield" changes everything
- 5:16Resume is back!
- 5:37The iterator protocol
- 6:38Generators implement this protocol
- 7:19Calling iter() gets an object's iterator
- 8:22"next" advances the generator
- 9:05fib
- 10:01read_n
- 11:11next_vowel
- 11:46So, when do we use generators?
- 13:33Using our generator with "send"
- 15:39How can I use coroutines?
- 16:11Coroutine as "nanoservices"
- 17:01Example: MD5
- 17:11Coroutine example 1: MD5
- 17:41Coroutine example 2: Weather
- 18:32Coroutine example 2.1: Weather
- 19:05When we get to the end of the list...
- 19:18The "throw" method
- 20:14Revisiting the weather
- 21:40Refactoring our generator
- 22:06"yield from" to the rescue!
- 23:39What about asyncio?
- 24:11Should you use coroutines?
- 24:46Questions?
related talks
42mAre generator-coroutines really the answer?
35mHow Do Python Coroutines Work?
01h 26mBeyond Python Enhanced Generators
41mMore About Generators
01h 29mStandardised Coroutine Concurrency in Python 3
01h 26mBeyond Python Enhanced Generators
01h 00mCoroutine Concurrency in Python 3 with asyncio
49mGenerators Will Free Your Mind
