Async Techniques and Examples in Python Transcripts
Chapter: Thread safety
Lecture: Threads are dangerous

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm sure you've heard about thread safety before, and there's things called race conditions and other problems
0:06 that threads can introduce into your programs. And the fact of the matter is, threads require extra, explicit safety measures.
0:15 We're going to talk about why that is and I've created a little visual graphic for you hopefully it really drives the point home for you.
0:22 But before we even get to the graphic I just want to say that the errors that you find in threading are extremely tricky
0:29 to track down in real programs. They're just super frustrating. The reason is, they depend on timing they depend on the hardware
0:37 they depend on the load on the system. They often have to do with one part of your system and another part getting either in sync
0:44 or out of sync in just a certain way based on a certain amount of load. And when you attach a debugger to that or you run an isolation on your machine
0:53 without all the extra load maybe those conditions don't recreate themself. Because of that, there's this really cute
0:59 and I think fairly appropriate name for these types of bugs they're often referred to as heisenbugs. Bugs that are there, until you observe them
1:08 and then that actually changes them and maybe they aren't there anymore this sort of weird, quantum mechanic duality.
1:13 If you think of quantum mechanics and that duality that's weird and hard to understand think of that in debugging, it makes it super hard.
1:19 So you want to be really careful about that and we're going to see the various constructs in Python that we have to work with
1:25 to make sure that the code we write doesn't have heisenbugs.


Talk Python's Mastodon Michael Kennedy's Mastodon