Skip to content

Commit ca9dda4

Browse files
committed
Most of the transcripts for the videos.
1 parent 4e8fea2 commit ca9dda4

File tree

89 files changed

+6096
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+6096
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
00:00 In this short chapter, we're going to talk about
2+
00:01 setting up your computer so that you can follow along.
3+
00:04 Do you have the right version of Python?
4+
00:06 What editors are you going to use?
5+
00:08 Can you get the source code
6+
00:09 to get started on some of the examples?
7+
00:11 Things like that.
8+
00:12 Obviously this is a Python course
9+
00:14 so you're going to need Python.
10+
00:16 But, in particular, you need Python 3.5 or higher.
11+
00:21 Now I would recommend the latest, Python 3.7.
12+
00:24 Maybe you're on a Linux machine, and it
13+
00:25 auto-updates as part of the OS, and that's probably 3.6.
14+
00:29 But you absolutely must have Python 3.5
15+
00:32 because that's when some of the primary
16+
00:34 async language features were introduced
17+
00:37 namely, the async and await keywords.
18+
00:41 Do you have Python, and if you do, what version?
19+
00:44 Well, the way you answer that question varies by OS.
20+
00:47 If you are on Mac or you're on Linux
21+
00:49 you just type 'python3 -V'
22+
00:52 and it will show you the Python version.
23+
00:54 In this screenshot, I had Python 3.6.5
24+
00:56 but in fact, 3.7 is out now
25+
00:57 so you might as well go ahead and use that one.
26+
01:00 But if you type this and you get
27+
01:01 an answer like 3.5 or above, you're good.
28+
01:04 If it errors out, you probably don't have Python.
29+
01:07 I'll talk about how to get it in a sec.
30+
01:09 Windows, it's a little less straightforward.
31+
01:12 You can type 'where python'
32+
01:14 and the reason you want to do that is
33+
01:16 there's not a way to target Python 3 in particular
34+
01:18 it just happens to be the first python.exe
35+
01:21 that lands in your path.
36+
01:23 So by typing 'where' you can see all the places
37+
01:25 and down here you can see I typed 'python -V' again
38+
01:27 same command but without the '3'
39+
01:29 and I got Python 3.6.5, the Anaconda version.
40+
01:32 That would be fine for this course
41+
01:34 Anaconda's distribution should be totally fine.
42+
01:37 But, again, has to be 3.5 or above.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
00:00 If you don't have Python
2+
00:01 or you have an older version of Python
3+
00:03 or you would just like to get a newer version of Python
4+
00:05 yes, you can go to python.org and download it
5+
00:08 but I recommend that you check out Real Python's article
6+
00:11 on installing and managing and upgrading Python.
7+
00:14 So just visit realpython.com/installing-python
8+
00:18 and check it out.
9+
00:19 The guys over there are putting lots of effort
10+
00:20 into keeping this up to date.
11+
00:22 For example, one of the ways you might want
12+
00:23 to install it on Mac OS would be to use Homebrew
13+
00:27 and that's different than what you get off of python.org.
14+
00:29 It let's you upgrade it a little more easily.
15+
00:31 That's the way I'm doing it these days
16+
00:32 and really liking it so far.
17+
00:34 So this article will help you find the best way
18+
00:36 to install it on your OS.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
00:00 In this course like most of our courses
2+
00:02 I'm going to be using PyCharm.
3+
00:04 Now you don't have to use exactly the same editor.
4+
00:06 You can use Visual Studio Code with a Python plug-in.
5+
00:09 You can use Emacs. You can use Vim.
6+
00:11 Whatever makes you happy.
7+
00:12 But if you want to follow along exactly.
8+
00:15 Then I recommend you use Pycharm.
9+
00:16 Now almost all of this course can be done
10+
00:18 in the Community Edition, the free edition of PyCharm.
11+
00:22 There is one chapter on web development.
12+
00:24 Maybe it's a little bit easier with PyCharm Pro
13+
00:27 but because we're not really working with CSS, JavaScript
14+
00:30 the template, anything like that
15+
00:32 I think you could actually use PyCharm Community Edition
16+
00:34 for the entire course. So if you want to use that
17+
00:38 just visit jetbrains.com/pycharm.
18+
00:41 Get it installed and I'll show you
19+
00:42 how to use it along the way.
20+
00:43 If you want to use something else, like I said, no problem
21+
00:45 use what makes you happy.
22+
00:47 Just be aware this is the one we're using
23+
00:48 so you have to adapt your editor and waverunning code
24+
00:51 to what we have over here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
00:00 You might consider what hardware
2+
00:02 you're taking this course on.
3+
00:03 Most of the time, the courses we have
4+
00:06 it doesn't matter what you're running on.
5+
00:07 You could probably take many of the courses
6+
00:09 we have on here, on say like, a Raspberry Pi
7+
00:12 or something completely small and silly like that.
8+
00:15 However, on this one
9+
00:17 you really need to have at least two cores.
10+
00:20 If you don't have two cores, you're not going to be able
11+
00:22 to observe some of the performance benefits
12+
00:25 that we talk about.
13+
00:27 So here's my machine, I have a MacBook Professional
14+
00:29 15 inch, 2018 edition with the Core i9
15+
00:33 which you can see 12 cores here.
16+
00:35 Six real cores, each of them hyper thread.
17+
00:37 So it appears as 12 to the operating system.
18+
00:40 But this system will really let us see a difference
19+
00:43 from when we're running on single threaded mode
20+
00:45 to parallel mode that actually takes advantage
21+
00:47 of all of the processors.
22+
00:49 But you don't have to have 12 cores.
23+
00:51 If you have two or four
24+
00:52 that will already let you see a difference
25+
00:54 but the more the better for this course
26+
00:57 because when we get to the performance section
27+
00:59 in particular, the CPU bound type of stuff
28+
01:02 we're trying to take advantage of the CPU
29+
01:04 you'll just see a bigger benefit, the more cores you have.
30+
01:07 So at least dual core is not required
31+
01:10 but to see some of the benefits
32+
01:11 you have to have more than one core.
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
00:00 Every single thing you see me type in this course
2+
00:02 will be available to you in GitHub.
3+
00:04 Before you go farther, pause the video and go over to
4+
00:07 GitHub.com/talkPython/async-techniques-python-course
5+
00:12 You can also just click the link to this GitHub
6+
00:15 repo in your course details page.
7+
00:18 You want to make sure you get access to this
8+
00:20 and go over there and star
9+
00:21 and consider forking it as well.
10+
00:23 That way you have a copy of exactly
11+
00:25 we're working with during this course.
12+
00:26 I encourage you to play around and write some code
13+
00:29 and try out the ideas from each chapter
14+
00:31 as we get to them.
15+
00:33 Most of the chapters have a starting and
16+
00:35 final version of code.
17+
00:37 So if you wanted to take, say, a serial
18+
00:40 single threaded computational little app
19+
00:42 that we build, and convert it to
20+
00:44 threads and convert it to
21+
00:45 multiprocessing, and things like that
22+
00:47 you'll have a copy over here on GitHub.
23+
00:49 So just be sure to star this, and
24+
00:51 consider forking it. Definitely check it out so
25+
00:53 you have access to it. If you don't do Git
26+
00:56 and that's fine, just click where it says
27+
00:58 clone or download, and
28+
00:59 download a zip, and then you'll have the
29+
01:00 source, as well.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
00:00 Let's begin our exploration of async by taking
2+
00:02 a really high-level view, we're going to look
3+
00:05 at the overall async landscape, some of the particulars
4+
00:09 about working with async in concurrent programming
5+
00:11 in Python, and the two main reasons that you care
6+
00:14 about asynchronous programming.
7+
00:16 In this first video we're going to focus on async for speed or
8+
00:20 for performance, the other main reason you might care
9+
00:23 about asynchronous programming or concurrent code would be
10+
00:26 for scalability, doing more at once.
11+
00:29 Right now we're going to focus on doing things faster
12+
00:32 for an individual series of computations.
13+
00:35 Later we're going to talk about scalability
14+
00:37 say for web apps and things like that.
15+
00:39 Let's look at some really interesting trends that have
16+
00:43 happened across CPUs in the last 10 years or so, 15 years.
17+
00:47 So here's a really great presentation by Jeffrey Funk
18+
00:50 over on SlideShare and I put the URL at the bottom
19+
00:52 you can look through the whole thing, you can see there's
20+
00:54 172 slides, but here I am pulling up one graphic that
21+
00:57 he highlights, because it's really, really interesting.
22+
01:01 See that very top line, that red line, that says
23+
01:03 transistors in the thousands, that is Moore's Law.
24+
01:07 Moore's Law said the number of transistors in a CPU
25+
01:11 will double every 18 months and that is surprisingly
26+
01:15 still accurate; look at that, from 1975 to 2015
27+
01:19 extrapolate a little bit, but still basically doubling
28+
01:23 just as they said.
29+
01:25 However people have often, at least in the early days
30+
01:28 thought of Moore's Law more as a performance thing
31+
01:31 as the transistors doubled, here you can see
32+
01:33 the green line "clock speed" and the blue line "single threaded
33+
01:37 performance" very much follow along with Moore's Law.
34+
01:40 So we've thought about Moore's Law means computers get
35+
01:44 twice as fast every 18 months and that was true more or less
36+
01:48 for a while, but notice right around 2008, around 2005
37+
01:53 it starts to slow and around 2008 that flattens off and
38+
01:57 maybe even goes down for some of these CPUs and
39+
02:00 the reason is we're getting smaller and smaller and smaller
40+
02:03 circuits on chips down to where they're basically
41+
02:05 at the point of you can't make them any smaller, you can't
42+
02:08 get them much closer both for thermal reasons and
43+
02:12 for pure interference reasons.
44+
02:14 You can notice around 2005 onward, CPUs are not getting
45+
02:19 faster, not really at all. I mean, you think back
46+
02:22 quite a bit and the speed of the CPU I have now is
47+
02:24 I have a really high-end one, it's a little bit faster but
48+
02:28 nothing like what Moore's Law would have predicted.
49+
02:30 So what is the take away?
50+
02:31 What is the important thing about this graphic?
51+
02:34 Why is Moore's Law still effective?
52+
02:37 Why are computers still getting faster, but the CPU and
53+
02:40 clock speed, really performance speed, single-threaded
54+
02:43 performance speed, is not getting faster, if anything
55+
02:45 it might be slowing down a little.
56+
02:47 Well that brings up to the interesting black graph
57+
02:50 at the bottom, for so long this was one core and
58+
02:53 then when we started getting dual-core systems and
59+
02:56 more and more CPUs, so instead of making the individual
60+
03:00 CPU core faster and faster by adding more transistors
61+
03:03 what we're doing is just adding more cores.
62+
03:05 If we want to continue to follow Moore's Law
63+
03:08 if we want to continue to take full advantage of the
64+
03:11 processors that are being created these days
65+
03:14 we have to write multi-threaded code.
66+
03:17 If we write single-threaded code, you can see it's either
67+
03:19 flat, stagnant, or maybe even going down over time.
68+
03:23 So we don't want our code to get slower, we want our code to
69+
03:26 keep up and take full advantage of the CPU it's running on
70+
03:29 and that requires us to write multi-threaded code.
71+
03:32 Turns out Python has some extra challenges, but
72+
03:35 in this course we will learn how to absolutely take
73+
03:38 full advantage of the multi-core systems that
74+
03:40 you're probably running on right now.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
00:00 Let's look at a real world example
2+
00:01 of a Python programming that is doing a very poor job
3+
00:05 taking advantage of the CPU it's running on.
4+
00:08 I'm running on my MacBook that I discussed
5+
00:10 in the opening, has 12 cores.
6+
00:13 This is the Intel i9 12 core maxed out
7+
00:18 you know, all nobs to 11 type of CPU
8+
00:20 for my MacBook Pro, here, so you can see
9+
00:22 it has a lot of processors. It has a lot of cores.
10+
00:27 In particular, has 12 hyper-threaded cores
11+
00:29 so six real cores, each one of which is hyper-threaded.
12+
00:34 Here we have a program running in the background
13+
00:35 working as hard as it can.
14+
00:37 How much CPU is the entire computer using? Well, 9.5%.
15+
00:43 If this were 10 years ago, on single core systems
16+
00:46 the CPU usage would be 100% but you can see
17+
00:49 most of those cores are dark, they're doing nothing
18+
00:53 they're just sitting there.
19+
00:54 That's because our code is written
20+
00:56 in a single-threaded way.
21+
00:58 It can't go any faster.
22+
00:59 Let's just look at that in action real quick.
23+
01:01 Now, this graph, this cool graph
24+
01:03 showing the 12 CPUs and stuff
25+
01:05 this comes from a program called Process Explorer
26+
01:09 which is a free program for Windows.
27+
01:10 I'm on my Mac, so I'll show you something
28+
01:12 not nearly as good but I really wanted to show you
29+
01:14 this graph because I think it brings home
30+
01:16 just how underutilized this system is.
31+
01:19 So let's go over here and we're going to run
32+
01:22 a performance or system monitoring tool
33+
01:25 actually built in Python
34+
01:26 which is pretty cool in and of itself, called Glances.
35+
01:29 So we're sorting by CPU usage, we're showing what's going on.
36+
01:33 We had a little Python running there, actually
37+
01:35 for a second, running probably in PyCharm
38+
01:37 which is just hanging out, but you can see the system
39+
01:39 is not really doing a whole lot, it is recording.
40+
01:41 Camtasia's doing a lot of work to record the screen
41+
01:43 so you have to sort of factor that out.
42+
01:46 Now, let's go over here and create another screen
43+
01:50 notice right here we have 12 cores.
44+
01:52 Okay, so if we run PtPython, which is a nicer REPL
45+
01:57 but just Python, and we write an incredibly simple program
46+
02:00 that's going to just hammer the CPU.
47+
02:03 Say x = 1, and then while true: x += 1.
48+
02:09 So we're just going to increment this, over and over and over.
49+
02:12 I'm going to hit go, you should see Python jump up here
50+
02:16 and just consume 100% of one core.
51+
02:19 This column here is actually measuring in
52+
02:24 single core consumption whereas this
53+
02:27 is the overall 12 core bit.
54+
02:31 Here it's working as hard as it can.
55+
02:33 You'll see Python'll jump up there in a second.
56+
02:37 Okay, so Python is working as hard as it can, 99.8%
57+
02:41 running out of my brew installed Python, there.
58+
02:44 But the overall CP usage, including screen recording
59+
02:48 on this whole system?
60+
02:50 11%, and of course as we discussed, that's because our code
61+
02:53 we wrote in the REPL, it only uses
62+
02:55 one thread, only one thread of concurrent execution
63+
02:59 that means the best we could ever possibly get is 1/12%.
64+
03:04 8.3% is the best we could ever do
65+
03:07 in terms of taking advantage of this computer
66+
03:10 unless we leverage the async capabilities
67+
03:12 that we're going to discuss in this course.
68+
03:14 So if you want to take advantage of modern hardware
69+
03:17 with multiple cores, the more cores the more demanding
70+
03:21 or more pressing this desire is
71+
03:24 you have to write concurrent multi-threaded code.
72+
03:27 Of course, we're going to see a variety of ways to do this
73+
03:29 both for I/O bound and, like this, CPU bound work
74+
03:33 and you handle those differently in Python
75+
03:35 which is not always true for other languages
76+
03:37 but it is true for Python.
77+
03:38 And by the end of this course, you'll know
78+
03:41 several ways to make, maybe not this simple, simple program
79+
03:45 but to make your Python program doing real computation
80+
03:48 push that up to nearly 100% so it's fully taking advantage
81+
03:52 of the CPU capabilities available to it.

0 commit comments

Comments
 (0)