Async Techniques and Examples in Python Transcripts
Chapter: Thread safety
Lecture: Threads are dangerous
0:00 I'm sure you've heard about
0:01 thread safety before, and there's things
0:03 called race conditions and other problems
0:05 that threads can introduce into your programs.
0:08 And the fact of the matter is, threads require
0:11 extra, explicit safety measures.
0:14 We're going to talk about why that is
0:16 and I've created a little visual graphic for you
0:18 hopefully it really drives the point home for you.
0:21 But before we even get to the graphic
0:22 I just want to say that the errors
0:24 that you find in threading are extremely tricky
0:28 to track down in real programs.
0:30 They're just super frustrating.
0:32 The reason is, they depend on timing
0:34 they depend on the hardware
0:36 they depend on the load on the system.
0:38 They often have to do with one part of your system
0:41 and another part getting either in sync
0:43 or out of sync in just a certain way
0:45 based on a certain amount of load.
0:47 And when you attach a debugger to that
0:49 or you run an isolation on your machine
0:52 without all the extra load
0:54 maybe those conditions don't recreate themself.
0:56 Because of that, there's this really cute
0:58 and I think fairly appropriate name for these types of bugs
1:02 they're often referred to as heisenbugs.
1:05 Bugs that are there, until you observe them
1:07 and then that actually changes them
1:08 and maybe they aren't there anymore
1:10 this sort of weird, quantum mechanic duality.
1:12 If you think of quantum mechanics and that duality
1:14 that's weird and hard to understand
1:15 think of that in debugging, it makes it super hard.
1:18 So you want to be really careful about that
1:19 and we're going to see the various constructs
1:22 in Python that we have to work with
1:24 to make sure that the code we write doesn't have heisenbugs.