|
| 1 | +00:00 Let's talk about the actual topics |
| 2 | +00:02 that we're going to cover chapter by chapter |
| 3 | +00:04 and how it all fits together. |
| 4 | +00:06 We're going to start digging further into why do we care |
| 5 | +00:09 about async, when should we use it, what are its benefits. |
| 6 | +00:12 So we're going to go way into it so you understand |
| 7 | +00:14 all the ways in which we might use asynchronous programming |
| 8 | +00:16 in Python, and when you might want to do that. |
| 9 | +00:19 Then it's time to start writing some code |
| 10 | +00:21 and making things concrete. |
| 11 | +00:23 We're going to focus first on the new key words introduced |
| 12 | +00:26 in Python 3.5 async and await. |
| 13 | +00:29 Now some courses leave this to the end |
| 14 | +00:31 as the great build-up, but I think you start here. |
| 15 | +00:34 This is the new, powerful way to do threading |
| 16 | +00:37 for anything that is waiting. |
| 17 | +00:39 Are you calling it database? |
| 18 | +00:41 Are you talking to a web service? |
| 19 | +00:42 Are you talking to the file system, things like that? |
| 20 | +00:45 We do these kinds of things all the time in Python |
| 21 | +00:47 and it' really not productive to just block our program |
| 22 | +00:50 while it's happening. We could be doing many other things. |
| 23 | +00:52 And the async and await key words in the asyncio foundation |
| 24 | +00:57 make this super straightforward. |
| 25 | +00:59 It's almost exactly the same programming model |
| 26 | +01:01 as the serial version |
| 27 | +01:03 but it's way more scalable and productive. |
| 28 | +01:06 Next we're going to focus on threads, sticking |
| 29 | +01:08 to making a single process more concurrent |
| 30 | +01:11 doing more at once. |
| 31 | +01:12 We're going to talk about a more traditional way |
| 32 | +01:15 of writing asynchronous code in Python with threads. |
| 33 | +01:18 We'll see sometimes this is super-productive. |
| 34 | +01:21 other times it's not as productive as you might hope |
| 35 | +01:24 especially because of things like the GIL raise its head. |
| 36 | +01:27 And we'll see when and how to deal with that. |
| 37 | +01:29 Some things are well-addressed with threads |
| 38 | +01:31 others not so much. |
| 39 | +01:33 When we start writing multithreaded code |
| 40 | +01:35 or asynchronous code, in general |
| 41 | +01:37 we have to think very carefully |
| 42 | +01:38 about the data structures that we use |
| 43 | +01:41 and making sure that we don't encourage a race conditions |
| 44 | +01:43 or deadlocks. |
| 45 | +01:44 So in this chapter we're going to talk about both of those. |
| 46 | +01:48 How do we prevent race conditions that might allow code |
| 47 | +01:51 to see invalid data or corrupt our data structures? |
| 48 | +01:53 And how do we prevent deadlocks |
| 49 | +01:55 from completely freezing up our program |
| 50 | +01:57 by the improper use of the tools trying |
| 51 | +01:59 to prevent the first? |
| 52 | +02:01 So we're going to talk a lot about thread safety |
| 53 | +02:02 make sure you get that just right. |
| 54 | +02:04 Now Python has two traditional types of parallelism |
| 55 | +02:07 threaded parallelism and process-based parallelism. |
| 56 | +02:10 And the primary reason we have this is because of the GIL. |
| 57 | +02:14 We'll see that threaded-based parallelism |
| 58 | +02:16 is great when you're waiting on things like databases |
| 59 | +02:18 or web calls, things like that. |
| 60 | +02:20 But it's basically useless for computational work. |
| 61 | +02:24 So if you wanta do something computational |
| 62 | +02:27 we're going to have to employ process-based parallelism. |
| 63 | +02:30 We're going to talk about Python's native, multiprocessing |
| 64 | +02:33 process-based parallelism, with tools all around |
| 65 | +02:37 that meant to take a bunch of work |
| 66 | +02:38 and spread it across processes. |
| 67 | +02:40 You'll see that the API for working with threads and the API |
| 68 | +02:43 for working with processes are not the same. |
| 69 | +02:46 But the execution pools are ways to unify these things |
| 70 | +02:50 so that our actual algorithms or actual code depend |
| 71 | +02:53 as little as possible on the APIs |
| 72 | +02:55 for either threads or processes, meaning we can switch |
| 73 | +02:58 between threads or processes depending on what we're doing. |
| 74 | +03:01 So we wanta talk about execution pools |
| 75 | +03:03 and how to unify those two APIs. |
| 76 | +03:07 Then we're going to see two really interesting libraries |
| 77 | +03:11 that take async and await and asyncio and make it better |
| 78 | +03:15 make it easier to fall into the pit of success. |
| 79 | +03:18 You just do the right thing, and it just happens. |
| 80 | +03:21 The way it guides you, things work better. |
| 81 | +03:23 So things like cancellation, parent/child tasks |
| 82 | +03:26 or any mix mode of, say, some IO-boundwork |
| 83 | +03:30 and some CPU boundwork. |
| 84 | +03:32 That can be really tricky, and we'll see some libraries |
| 85 | +03:34 that make it absolutely straightforward and obvious. |
| 86 | +03:37 One of the great places we would like |
| 87 | +03:39 to ply asyncio is on the web. |
| 88 | +03:42 That's a place where we're waiting on databases |
| 89 | +03:44 and other web services all the time. |
| 90 | +03:46 We'll see the traditional, popular frameworks |
| 91 | +03:49 like Django, Flask, Pyramid do not support any form |
| 92 | +03:53 of asynchrony on the web. |
| 93 | +03:55 So we'll take something that is a Flask-like API |
| 94 | +03:58 and adapt it to use asyncio |
| 95 | +04:00 and it's going to be really, really great. |
| 96 | +04:01 We'll see massive performance improvements |
| 97 | +04:03 around our web app there. |
| 98 | +04:05 Finally, we'll see that we can integrate C with Python |
| 99 | +04:09 and, as you know, C can do just about anything. |
| 100 | +04:12 Your operating system is written in C. |
| 101 | +04:14 It can do whatever it wants. |
| 102 | +04:16 So we'll see that C is actually a gateway |
| 103 | +04:18 to a different aspect, different type |
| 104 | +04:21 of parallelism and performance in Python. |
| 105 | +04:23 But we don't wanta write C. |
| 106 | +04:25 Maybe you do, but most people don't want to write C |
| 107 | +04:27 if they're already writing Python. |
| 108 | +04:28 So we'll see that we can use something called Cython |
| 109 | +04:31 to bridge the gap between C and Python |
| 110 | +04:33 and Cython has special key words to unlock C's parallelism |
| 111 | +04:38 in the Python interpreter. |
| 112 | +04:40 It's going to be great. |
| 113 | +04:41 So this is what we're covering during this course |
| 114 | +04:43 and I think it covers the gamut |
| 115 | +04:45 of what Python has to offer for asynchronous programming. |
| 116 | +04:49 There's so much here; I can't wait |
| 117 | +04:51 to get started sharin' it with you. |
0 commit comments