Async Techniques and Examples in Python Transcripts
Lecture: Concept: Tips for multiple threads
0:00 We saw a few nice little techniques
0:01 for working with sets of threads
0:03 more than one thread at a time.
0:05 So let's suppose that we're going to create
0:08 three threads and we want to work with them as a set.
0:10 Basically we want to spin those three off
0:12 and then we're going to start them
0:14 and then wait for them all to finish.
0:15 So we did that in our producer consumer example
0:18 while having a list of threads
0:20 and we create them all
0:21 and just in line like this.
0:22 We could do it in a loop.
0:23 Append if you wanted.
0:24 But in this case
0:25 we didn't need to do that.
0:27 Next we're going to start them all
0:28 using this cool little list comprehension.
0:31 t.start() for t in threads.
0:33 Potentially do some other work
0:35 and then wait for them to finish.
0:37 So t.join() for t in threads.
0:40 Pretty simple right.