Async Techniques and Examples in Python Transcripts
Lecture: Visual of thread execution
0:00 It's always good to have a picture of what's going on
0:02 in our code, in our programs as they run.
0:05 Here's a picture that I drew
0:07 trying to simulate that, or visualize that
0:10 for you in Python.
0:11 So, this big box is our process
0:14 and the process itself can kickoff different threads.
0:18 And those are the little gray arrows.
0:20 The ..., that's just waiting.
0:22 We have our main program is running
0:24 and then at some point it kicks off two additional threads
0:26 does a little more work
0:27 then waits for the two threads to finish
0:29 and then carries on working.
0:31 So, this fork-join pattern, kick a bunch of work off
0:34 wait for it to finish, and then carry on
0:36 is very common in threaded programing.
0:39 And it's important to realize
0:40 these threads are all in the same process.
0:42 They all work on the same memory.
0:44 So, if I have a variable or a data structure in Python
0:47 which is always the pointer
0:48 pointers are shared data structures
0:50 per process in the global memory heap.
0:52 If I have one of those, and different threads
0:55 are working with it, it's the exact same object.
0:59 So we'll have to see, you're going to have to be
1:00 kind of careful with your data structures
1:02 and the state of your program.
1:04 When you're doing programing with threads in Python.
1:06 So, here's a picture to keep in mind
1:08 to help you visualize typically what's happening
1:10 with our threads in Python.