Async Techniques and Examples in Python Transcripts
Chapter: async and await with asyncio
Lecture: Concept: asyncio

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that you've seen our asyncio example in action let's look at the anatomy of an async method. Remember there's two core things we have to do.
0:09 We begin by making the method async. So we have a regular method def method name and so on. To make it async you just put async in front.
0:18 Remember requires Python 3.5 or higher. And then you're going to await all of the other async calls that you make so anytime within this method
0:27 if you're going to call it another async method you have await it. And that tells Python here is a part, a slice of this job
0:35 and you can partition with other slices of other jobs in the asyncio event loop. So we know that get is an async method.
0:44 Python didn't help us this time very much on this one but if you go to the definition you'll see and also we didn't actually get a tuple back
0:50 we got a coroutine, so that's a dead giveaway there. And that's pretty much it. You don't really have to do much differently at all.
0:57 The most important thing is that anytime you can that you use some sort of method that actually supports asynchronous calls.
1:05 So if you're talking to a database try to find the driver that supports asynchronous operations and so on. We're going to talk more about that later
1:12 as we get farther in the class but the more times you can await stuff the more fine-grain the work will be probably the better.

Talk Python's Mastodon Michael Kennedy's Mastodon