Generators, coroutines, and nanoservices: Understanding and usingView
Reuven Lerner is a full-time Python trainer. In a given year, he teaches courses at companies in the United States, Europe, Israel, India, and China — as well as to people around the world, via his online courses, including Weekly Python Exercise.
Reuven’s monthly column appeared in Linux Journal from 1996 until the magazine closed in 2019. He was a panelist on the Freelancers Show for five years, and is now a panelist on the Business of Freelancing Podcast. Reuven's book, "Python Workout," published by Manning.
Reuven’s most recent book is “Python Workout,” a collection of Python exercises with extensive explanations, published by Manning.
Reuven’s free, weekly Better developers newsletter, about Python and software engineering, is read by more than 16,000 developers around the globe. His “Trainer weekly” newsletter is similarly popular among people who give corporate training.
Reuven has a bachelor’s degree in computer science and engineering from MIT, and a PhD in learning sciences from Northwestern University. He lives in Modi’in, Israel with his wife and three children.
Generators, coroutines, and nanoservices: Understanding and using
Generator functions have been a part of Python for many years already, and are a well known technique for creating iterators. But generators have a few lesser-known aspects, including their "send" method and the "yield from" syntax. Many Python developers shy away from using them, unsure of what they would do, or how they would be useful — seeing coroutines as a solution looking for a problem.
In this talk, I'll tell you why coroutines can be useful, and how thinking about them as in-process "nanoservices" puts us in the right frame of mind to determine when they would and wouldn't be appropriate. Among the topics we'll explore are:
- Generator function basics
- next vs. send
- How to build a coroutine
- Thinking of coroutines as nanoservices
- The need for `yield from`
- Using `yield from`
- Ideas for general usage