#100DaysOfWeb in Python Transcripts
Chapter: Days 21-24: Async Flask APIs with Quart
Lecture: Asynchronous execution concepts

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's look at the order and timing of operations. Imagine we have asynchronous execution like we just saw. So again, we have request one, two and three
0:10 coming in on exactly the same timing. They take exactly the same amount of time to run. But when we dug into the requests we saw most of the time
0:20 we're waiting on a database or something else right like a web service. So during those times, maybe our requests
0:26 actually could just run almost truly in parallel. Notice, for example, when request three comes in we couldn't quite run it
0:33 exactly when that request came in but it's pretty close because soon request one and two went back to waiting on the database.
0:40 So again, let's look at the timing here. So, we have our request one come in. And, of course, just like before it got done right when it did
0:48 in fact maybe just took a hair longer cause it gave up its time and couldn't quite get it back from two
0:54 right when it was ready to run, somethin like that. But we have our response time roughly the length of request one. But now, when request two comes in
1:03 we saw that request one was waiting on the database so it could immediately start running. And it got done more or less
1:08 in the same amount of time it took. And request three was, actually its response was moved up ahead of request two.
1:16 So from a response perspective, it went one, three, two because three was really short and one and two were waiting on the database.
1:23 So, boom one, two, three and it could just get that out of the way. So the response time per request from the outside
1:29 one, two, and three, looked much more like what they would be if there was just one user to the site even though it was theoretically really busy.
1:38 Now if we dig in again like we did before we'll see that yes, we're still doing framework database
1:43 code, maybe web services which I haven't highlighted here. But now the database section is green because during those times, we're telling Python
1:51 via our async and await programming you know what? I'm just waiting here. If you've got other stuff to do other requests or processes
1:59 feel free to go work on them until they start to wait. And then let me come back and run my code. That's the beauty of async programming.
2:05 This is a really powerful concept in Python in general. And it happens to be really useful on the web
2:11 because a lot of time, what you're doing on the website is waiting on a database, waiting on an external service
2:17 something like that. You can make that productive waiting time. So that's an overview of asynchronous programming in Python.


Talk Python's Mastodon Michael Kennedy's Mastodon