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

Google, IBM & Meta Certificates – 40% Off
One Coursera Plus subscription covers most Professional Certificates on Coursera.
Unlock All Certificates
This talk explores Python generators and their less familiar features, including send, throw, and yield from. It uses examples such as MD5 and weather coroutines to show when coroutines can be useful as in-process nanoservices.

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.