Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Generators, Coroutines and Nanoservices

PyCon US via YouTube

Overview

Explore the advanced features of Python generators, coroutines, and their practical applications in this 26-minute PyCon US talk. Dive into the lesser-known aspects of generators, including the "send" method and "yield from" syntax. Learn how to conceptualize coroutines as in-process "nanoservices" and discover when they are most appropriate to use. Examine real-world examples, such as implementing MD5 hashing and weather data processing, to understand the power of these Python constructs. Gain insights into refactoring generators, handling exceptions with the "throw" method, and leveraging the "yield from" statement for cleaner code. Conclude with a brief discussion on asyncio and guidelines for effectively incorporating coroutines into your Python projects.

Syllabus

Intro
I teach Python!
The dumbest function in the world
Bytecode from our function
Resume?
"yield" changes everything
Resume is back!
The iterator protocol
Generators implement this protocol
Calling iter() gets an object's iterator
"next" advances the generator
fib
read_n
next_vowel
So, when do we use generators?
Using our generator with "send"
How can I use coroutines?
Coroutine as "nanoservices"
Example: MD5
Coroutine example 1: MD5
Coroutine example 2: Weather
Coroutine example 2.1: Weather
When we get to the end of the list...
The "throw" method
Revisiting the weather
Refactoring our generator
"yield from" to the rescue!
What about asyncio?
Should you use coroutines?
Questions?

Taught by

PyCon US

Reviews

Start your review of Generators, Coroutines and Nanoservices

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.