~/talk

Generators, coroutines and nanoservices

Talkat PyCon US 2023 · 2023-04-19..04-27· [python, frontend-architecture]
slides:none on file

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

  1. 0:00Intro
  2. 0:29I teach Python!
  3. 1:33The dumbest function in the world
  4. 2:31Bytecode from our function
  5. 3:04Resume?
  6. 4:01"yield" changes everything
  7. 5:16Resume is back!
  8. 5:37The iterator protocol
  9. 6:38Generators implement this protocol
  10. 7:19Calling iter() gets an object's iterator
  11. 8:22"next" advances the generator
  12. 9:05fib
  13. 10:01read_n
  14. 11:11next_vowel
  15. 11:46So, when do we use generators?
  16. 13:33Using our generator with "send"
  17. 15:39How can I use coroutines?
  18. 16:11Coroutine as "nanoservices"
  19. 17:01Example: MD5
  20. 17:11Coroutine example 1: MD5
  21. 17:41Coroutine example 2: Weather
  22. 18:32Coroutine example 2.1: Weather
  23. 19:05When we get to the end of the list...
  24. 19:18The "throw" method
  25. 20:14Revisiting the weather
  26. 21:40Refactoring our generator
  27. 22:06"yield from" to the rescue!
  28. 23:39What about asyncio?
  29. 24:11Should you use coroutines?
  30. 24:46Questions?
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.